and if you expand upon this approach you'll probably have column conflicts too, refer to http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/declarative.html#resolving-column-conflicts for the strategy for dealing with that.
On Jan 14, 2013, at 1:17 PM, Michael Bayer wrote: > The inheritance mechanics don't support multiple inheritance from the POV of > multiple mapped classes as the base for another mapped class. Single table > inheritance would be the easiest case to work at some point, but there's lots > of mechanics in place right now that assume a linear path from subclass to > superclass. > > If you don't actually need instances of EvidenceString, EvidenceAmount, and > EvidenceQuantity to exist in the database distinctly (that is, you'd never > actually have any rows with "string", "amount", or "quantity" present in the > DB as the discriminator), you'd define these as unmapped mixins, which is > very well supported (see > http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/declarative.html#mixin-and-custom-base-classes) > . It seems here like that's what you're really looking for. > > > > On Jan 14, 2013, at 1:09 PM, Ethan Fremen wrote: > >> I have a pretty simple case. A base class with three sub-classes, and then a >> final class that inherits from the three derived classes. When persisting, >> sqlalchemy only sets the properties of the parent class and the first child >> class. >> >> In all other respects the sub-class is behaving properly; it has the correct >> attributes, etc. >> >> So, if EvidenceLineItem inherits from EvidenceString first, only the string >> property (and the properties in Evidence) will update; if I change the first >> inherited class to EvidenceAmount, amount will be persisted, but the rest >> not. >> >> I'll try declared_attr, but I'm pretty sure that this behaviour isn't what >> is intended. >> >> ~ethan >> >> class Evidence(Base): >> __tablename__ = "evidence" >> discriminator = Column(DBEnum(ProofItemClassType), nullable=False) >> __mapper_args__ = { 'polymorphic_on': discriminator, >> 'polymorphic_identity': ProofItemClassType.generic } >> >> class EvidenceString(Evidence): >> __mapper_args__ = { 'polymorphic_identity': ProofItemClassType.string } >> string = Column(String(length=255), index=True) >> >> class EvidenceAmount(Evidence): >> __mapper_args__ = { 'polymorphic_identity': ProofItemClassType.amount } >> amount = Column(Numeric(precision=7, scale=2), index=True) >> >> class EvidenceQuantity(Evidence): >> __mapper_args__ = { 'polymorphic_identity': ProofItemClassType.quantity } >> quantity = Column(Integer) >> >> class EvidenceLineItem(EvidenceString, EvidenceAmount, EvidenceQuantity): >> __mapper_args__ = { 'polymorphic_identity': ProofItemClassType.line_item >> } >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/sqlalchemy/-/5hEAmVfC-EYJ. >> To post to this group, send email to sqlalchemy@googlegroups.com. >> To unsubscribe from this group, send email to >> sqlalchemy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sqlalchemy?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.