- changed milestone to 0.x.xx
add example of declared_attr columns shared across inheritance to declarative docs
Issue #2471
resolved
i.e.
class InheritMixin(object):
@declared_attr
def __tablename__(cls):
return cls.__name__
@declared_attr
def id(cls):
return Column(Integer, primary_key = True)
@declared_attr
def __mapper_args__(cls):
if not has_inherited_table(cls):
return {'polymorphic_on': 'discriminator'}
else:
return {'polymorphic_identity': cls.__name__}
class Inherits(InheritMixin):
@declared_attr
def id(cls):
super_id = super(Inherits, cls).id
return Column(Integer, ForeignKey(super_id),primary_key = True)
class Person(InheritMixin, Base):
discriminator = Column(String(50))
name = Column(String(50))
class Engineer(Inherits, Person):
job = Column(String(50))
Comments (3)
-
reporter -
reporter - changed status to wontfix
i dont see why this pattern is special for the main docs
-
reporter - changed milestone to 1.x.xx
- Log in to comment
im a little shaky on this as the pattern doesn't work with more than one level of inheritance.