From 7d56f6c8077a3d9aeae3aed2cc548ca4e350161b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 10 Feb 2014 17:43:37 -0500 Subject: [PATCH] this example doesn't work, we don't really have a solution for this as far as automating this pattern --- lib/sqlalchemy/ext/declarative/__init__.py | 31 ---------------------- 1 file changed, 31 deletions(-) diff --git a/lib/sqlalchemy/ext/declarative/__init__.py b/lib/sqlalchemy/ext/declarative/__init__.py index 0ee4e33fd4..e878e362da 100644 --- a/lib/sqlalchemy/ext/declarative/__init__.py +++ b/lib/sqlalchemy/ext/declarative/__init__.py @@ -1122,37 +1122,6 @@ inheritance:: primary_language = Column(String(50)) __mapper_args__ = {'polymorphic_identity': 'engineer'} -If you want to use a similar pattern with a mix of single and joined -table inheritance, you would need a slightly different mixin and use -it on any joined table child classes in addition to their parent -classes:: - - from sqlalchemy.ext.declarative import declared_attr - from sqlalchemy.ext.declarative import has_inherited_table - - class Tablename(object): - @declared_attr - def __tablename__(cls): - if (has_inherited_table(cls) and - Tablename not in cls.__bases__): - return None - return cls.__name__.lower() - - class Person(Tablename, Base): - id = Column(Integer, primary_key=True) - discriminator = Column('type', String(50)) - __mapper_args__ = {'polymorphic_on': discriminator} - - # This is single table inheritance - class Engineer(Person): - primary_language = Column(String(50)) - __mapper_args__ = {'polymorphic_identity': 'engineer'} - - # This is joined table inheritance - class Manager(Tablename, Person): - id = Column(Integer, ForeignKey('person.id'), primary_key=True) - preferred_recreation = Column(String(50)) - __mapper_args__ = {'polymorphic_identity': 'engineer'} Combining Table/Mapper Arguments from Multiple Mixins ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- 2.47.3