On May 1, 2008, at 6:25 PM, Bobby Impollonia wrote:
> class Parent(Base): > __tablename__ = 'parent' > id = Column('id', Integer, primary_key=True) > tp = Column('type', String(50)) > __mapper_args__ = dict(polymorphic_on = tp) > > class Child1(Parent): > __tablename__ = 'child1' > id = Column('id', Integer, ForeignKey('parent.id'), > primary_key=True) > related_child2 = Column('c2', Integer, ForeignKey('child2.id', > use_alter = True, name='c2_key')) > __mapper_args__ = dict(polymorphic_identity = 'child1') > > class Child2(Parent): > __tablename__ = 'child2' > id = Column('id', Integer, ForeignKey('parent.id'), > primary_key=True) > related_child1 = Column('c1', Integer, ForeignKey('child1.id')) > __mapper_args__ = dict(polymorphic_identity = 'child2') You have two tables that have a mutual dependence on each other, and when Child1 atttempts to configure its table join against Parent, the table arithmetic loads up and can't resolve the "child2.id" foreign key, since Child2 hasn't been defined yet. In this particular case, you can have it skip the step thats failing by putting an explicit inherit condition on Child1: __mapper_args__ = dict(polymorphic_identity = 'child1', inherit_condition=Parent.id==id) Or use explicit Table objects defined outside of the classes. many versions ago before we had declarative, the "inheritance" compilation happening here would be deferred until all mappers were set up, but we simplified everything at some point so that very little of mapper compilation had to be deferred. It appears that declarative re-introduces that need to some degree here, so I would consider this a bug. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---