On Jun 26, 2010, at 7:28 AM, Michel Albert wrote:

> 
> Thanks for the answer. From the docs, this seems to be what I am
> looking for. But it sill isn't quite giving me what I want. For
> reference, here's the mapper:
> 
> mapper( Item, item, properties={
>   'owner': relation( Contact, backref='owned_items',
>      primaryjoin=item.c.owner_id==contact.c.contact_id,
>      passive_deletes="all"),
>   'holder': relation( Contact, backref='held_items',
>      primaryjoin=item.c.holder_id==contact.c.contact_id,
>      passive_deletes=True ),
>   } )
> 
> In the case of my application I want owner to be a "compulsory"
> relation, and "holder" an optional one. So, if an "owner" gets
> deleted, I want all items to be removed as well. For that I have the
> "ON DELETE CASCADE" rule in the DB.

SQLA wants to know about that so you'd also include cascade="all, 
delete-orphan" on the relationship.   passive_deletes then gets set just to 
"True", so that it won't load unloaded rows unnecessarily.


> On the other hand however, as
> holders are optional they should simply be set to NULL if the related
> contact disappears.

and on that one you leave the usual UPDATE behavior in place.

> This is why I used the two different values for
> "passive_deletes". The way I understand the docs, having
> passive_deletes set to True or "all" let's the DB handle referential
> integrity.

But SQLA still needs to know what it should do with objects that are present in 
the session.  "passive_deletes" doesn't mean "won't touch it". It means, "won't 
load unloaded rows to make sure they are also deleted".    I just re-read the 
mapping and API docs for it and to me they appear to be pretty clear on that 
point.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.

Reply via email to