15 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: problem with backref
FromSent OnAttachments
Manlio Perillo20 Dec 2006 01:39 
Manlio Perillo20 Dec 2006 02:06 
Alan Franzoni20 Dec 2006 08:25 
Manlio Perillo20 Dec 2006 13:06 
Alan Franzoni20 Dec 2006 16:23 
Michael Bayer20 Dec 2006 16:49 
Manlio Perillo21 Dec 2006 01:56 
Manlio Perillo21 Dec 2006 02:00 
Alan Franzoni21 Dec 2006 04:48 
Lee McFadden21 Dec 2006 05:10 
Michael Bayer21 Dec 2006 08:17 
Manlio Perillo23 Dec 2006 03:08 
Michael Bayer23 Dec 2006 16:32 
Michael Bayer23 Dec 2006 18:53 
Manlio Perillo24 Dec 2006 02:27 
Subject:[sqlalchemy] Re: problem with backref
From:Michael Bayer (zzz@gmail.com)
Date:12/20/2006 04:49:06 PM
List:com.googlegroups.sqlalchemy

the original mapping essentially expressed this relationship:

A <-- cascade="all, delete-orphan" --> B

in both directions. What that means is, there cannot be an A with no B in the database, and there cannot be a B with no A in the database, i.e. its either A<->B or both will be deleted. its like an oxygen molecule, or something.

what you need to do is decide which of A and B can exist on its own without a parent relationship. since you want to delete rows from B and not A, that would indicate that the mapping should be:

mapper(A, a) mapper( B, b, properties={ 'a': relation( A, backref=backref('b', lazy=False, uselist=False, cascade='all, delete-orphan'), uselist=False ) } )

i.e. the "delete-orphan" cascade is only in the direction from A->B. the cascade from B->A is left at its default value of "save-update", so delete operations dont propigate from B's to A's.