ive thought about this and it might be the kind of thing we just add a flag on mapper() for. I had exactly this same issue with a project I did for someone. The solution I gave below works, but needs to be called only after compile_mappers() is called.
On Feb 23, 2009, at 5:16 PM, Michael Bayer wrote: > > there is not, you'd have to do something along the lines of: > > for prop in local_mapper.iterate_properties: > getattr(local_mapper.class_, prop.key).impl.active_history = > True > > > On Feb 23, 2009, at 4:18 PM, kindly wrote: > >> >> This did not end up working as, I think, active_history is by default >> false. Is there a way in a mapper to set this for all attributes to >> be True? Its a shame as any AttributeExtension will fix this as they >> imply True. >> >> >> On Feb 18, 3:23 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: >>> get_history() is a public function within the attributes package at >>> the top level, and I also added API documentation for it recently >>> (not >>> on the site yet). >>> >>> from sqlalchemy.orm.attributes import get_history, instance_state >>> >>> get_history(instance_state(myobject), "someattribute") >>> >>> in the latest trunk you can pass "myobject" straight to get_history >>> without using instance_state. >>> >>> session.is_modified() just calls get_history() on every attribute, >>> so >>> you might want to consider just looping through the attributes the >>> way >>> is_modfied() does and do your history operation inline. >>> >>> On Feb 18, 2009, at 9:43 AM, kindly wrote: >>> >>> >>> >>>> Hello >>> >>>> I intend to log any changes (not new rows) to a table. >>> >>>> The simplist way I can see to do this is to check every object >>>> that is >>>> "add"ed for changes. I intend to, before every flush, look in >>>> "dirty" >>>> then use is_modified and if there is a change use get_history to >>>> find >>>> out the original and new attribute values. I am wary of doing it >>>> this >>>> way as _sa_instance_state looks private even though get_history is >>>> not. Should this be safe to use? Or is there a better way? >>> >>>> Thanks >>> >>>> David >>> > > > > --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---