On Sep 28, 2007, at 3:08 AM, Aaron R wrote:

>
> Hello;
>
> Does anyone know what the behavior for the before_update and
> before_insert methods of a mapper that is extended should be?  From
> the code below, if i add a child object to an item being saved during
> a before_insert that has a mapper extension it is not saved, but is if
> session.save() is subsequently called?   However changes made to the
> core attributes are saved, just not list items.  Is that the expected
> behavior?  If so is there an earlier event to catch and do an
> equivalent?
>

the before_insert() and before_update() methods are called in the  
context of an ongoing flush() operation.  inside of flush(), the full  
graph of objects to be inserted/updated/deleted has already been  
determined, so you cannot affect that graph within before_insert or  
before_update.  changes which you make to the session at that stage  
wont get picked up until the next flush.

however, the column-based attributes present on the instance itself  
have not yet been inserted/updated into the DB, and the fact that the  
instance is being sent to before_update() indicates that it has in  
fact already been marked as "dirty" and is to be updated.  So  
whatever column-attribute changes you make within before_update to  
the local instance will be reflected in the immediately proceeding  
SQL statement.

if youd like to make changes to the total graph of objects before a  
flush, theres a SessionExtension object you can use in version 0.4 in  
order to add hooks to the flush process.




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