Hello, here is a sample: children_table = Table('children', metadata, Column('id', Integer, primary_key=True)) child2group_table = Table('child2group', metadata, Column('child_id', Integer, ForeignKey('children.id'), nullable=False), Column('group_id', Integer, ForeignKey('groups.id'), nullable=False)) groups_table = Table('groups', metadata, Column('id', Integer, primary_key=True))
mapper(Child, children_table, properties={ 'groups':relation(Group, secondary=child2group_table) }) mapper(Group, groups_table, properties={ 'children':relation(Child, secondary=child2group_table) }) Speaking English, this means "there are groups and children, and child can belong to some groups". When I issue this: group = session.query(Group).get(2) session.delete(group) session.flush() SA does this: 2007-09-03 11:40:25,915 INFO sqlalchemy.engine.base.Engine.0x..8c BEGIN 2007-09-03 11:40:25,918 INFO sqlalchemy.engine.base.Engine.0x..8c DELETE FROM child2group WHERE child2group.child_id = ? AND child2group.group_id = ? 2007-09-03 11:40:25,918 INFO sqlalchemy.engine.base.Engine.0x..8c [[3, 2], [4, 2]] 2007-09-03 11:40:25,919 INFO sqlalchemy.engine.base.Engine.0x..8c DELETE FROM groups WHERE groups.id = ? 2007-09-03 11:40:25,920 INFO sqlalchemy.engine.base.Engine.0x..8c [2] 2007-09-03 11:40:25,921 INFO sqlalchemy.engine.base.Engine.0x..8c COMMIT Well, I dont mind, because this is what I really wanted to have. Please, explain, why does this happen? I thought only group item would be deleted and I would get orphaned records in child2group table. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---