On Oct 22, 2008, at 2:05 PM, GustaV wrote:

>
> Hi all!
>
> In a 1-N relation between a country and its regions, I'm using an
> attribute extension to update the current count of regions into
> countries. It works very well when I append or remove regions from
> country.
> But if I delete one of the region directly (session.delete(region)),
> the country doesn't know it has lost one...
>
> I tried to use a MapperExtension.before_delete to manually remove the
> said region from the country, but it is not marked as "dirty" and then
> not updated...
>
> Any way to do it properly?

for a one-to-many relation, its often easy enough to just have a  
cascade rule from country->region such that region is deleted  
automatically when removed from the parent.   This is the typical way  
to go about deletions from relations, since session.delete() does not  
cascade "backwards" to all owning collections.

although when I deal with columns that "count" something that is  
elsewhere represented in the database, I often issue these using SQL  
within a SessionExtension.after_flush().  This removes the need to  
worry about catching attribute events and just directly sets the  
correct value based on the state of the transaction post-flush.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to