On Dec 27, 2008, at 10:29 AM, Jim Jones wrote:

>
> Andreas Jung wrote:
>> On 27.12.2008 11:06 Uhr, Jim Jones wrote:
>>> Hi List,
>>>
>>> I have this simple model (in declarative style):
>>>
>>> class Item( Base ):
>>>     __tablename__ = 'items'
>>>     desc  = Column( 'desc', UnicodeText(), nullable=False )
>>>     email = Column( 'email', UnicodeText(), nullable=False )
>>>
>>> How can I trigger an event when the value of 'desc' has changed
>>> and the instance is persisted (e.g. via 'session.save(item)')?
>>
>> Please check the SA docs on using the decl. layer. It tells you how
>> to define your own get/set methods using the property mechanism.
>
> Yes, I know about properties but as I understand it they fire when
> the value is set and not when the instance is persisted.
>
> I would like to make sure that my handler only fires when the change
> is actually written to the database - to avoid triggering it multiple
> times when the attribute is assigned to multiple times before save()
> for whatever reason.

you can use MapperExtension insert/update events for this.  However,  
if you're sending an email based on something being saved, you might  
want to wait until after the transaction has completed for this to  
occur.  For that you can use SessionExtension.after_commit().


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