Christian Schwanke wrote: > metadata = MetaData() > table_a = Table('table_a', metadata, > Column('id', Integer(), primary_key=True), > Column('name', String(20), nullable=True), > ) > > table_b = Table('table_b', metadata, > Column('a_id', Integer(), nullable=False, primary_key=True), > Column('id', Integer(), nullable=False, primary_key=True), > Column('name', String(20), nullable=True), > ForeignKeyConstraint(['a_id'], ['table_a.id'], > ondelete='CASCADE'), > ) > > table_c = Table('table_c', metadata, > Column('a_id', Integer(), nullable=False, primary_key=True), > Column('b_id', Integer(), nullable=False, primary_key=True), > Column('id', Integer(), primary_key=True), > Column('name', String(20), nullable=True), > ForeignKeyConstraint(['a_id', 'b_id'], ['table_b.a_id', > 'table_b.id'], ondelete='CASCADE'), > ) > # Mapping > mapper(ItemA, table_a, properties={'b': relation(ItemB, backref="a", > cascade="all, delete-orphan")}) > mapper(ItemB, table_b, properties={'c': relation(ItemC, backref="b", > cascade="all, delete-orphan")}) > mapper(ItemC, table_c)
relation ItemC.b takes care of the assignment of table_c.b_id, but there is nothing here for SQLA to know about table_c.a_id. You need another relation() on ItemC which expresses this, and you need to assign itemA1 to ItemC explicitly, independently of the ItemB stuff. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---