Re: Getting changes applied to an object to build an history
James Henstridge <james@...
2011-10-27 03:46:25 GMT
On Fri, Oct 21, 2011 at 1:25 AM, Vincent Alquier
> First of all, sorry for my approximate english...
> For a project I am currently working on, I am trying to migrate from a
> homemade ORM to storm. One of my needs is to get all changes applied
> to an object on flush. The goal is to fill an history table with any
> Is it safe to call Store._get_changes_map into the __storm_pre_flush__
> hook ? And then, to save the changes into the __storm_flushed__ hook ?
The underscore at the start of the _get_changes_map() method indicates
that the method is private, so it would be better to find some other
method to do what you want.
One thing to keep in mind is that it is possible to make changes in
Storm that won't trigger these flush hooks, such as through the
ResultSet.set() method (which generally corresponds to an UPDATE
statement acting on rows that may or may not have Python
representations), so if you require all changes to be recorded, you
might be best off going with database level triggers.
If you can't use triggers, and are not going to use the bulk update
operations Storm provides, then perhaps the validator feature might
cover your needs? If you attach a validator to a property it will be
called each time there is a change, so you could use that to record
which fields have been changed.