On Aug 21, 2013, at 12:40 PM, Hans-Peter Jansen <h...@urpla.net> wrote:

> Hi,
>  
> being new to SQLAlchemy, I try to get my way through it.
>  
> In an application, I have rather elaborate needs to track changes.
>  
> I've defined 3 classes with declarative, where the main class has 
> relationships with two auxiliary classes, that refer to the main class with 
> foreign references. All pretty basic stuff.
>  
> Now I need to track all modifications to all fields, including the 
> relationship list objects. 
>  
> What is the best way to accomplish this task with SQLAlchemy?
>  
> Is there some boilerplate available to support this, or do I have to carry 
> around two objects and compare them item by item?

you can intercept changes on attributes using the attribute event system:  
http://docs.sqlalchemy.org/en/rel_0_8/orm/events.html#attribute-events

otherwise you can get at the changes on an attribute after the fact (but before 
a flush) using the history interface: 
http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html?highlight=history#sqlalchemy.orm.attributes.History

you can get a list of all attributes mapped using mapper.attrs: 
http://docs.sqlalchemy.org/en/rel_0_8/orm/mapper_config.html?highlight=mapper.attrs#sqlalchemy.orm.mapper.Mapper.attrs


Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to