Michael Bayer wrote:
for thing in session.query(MyThing).all():
...   print x.id, x.name, x.value, x.valid_from, x.valid_to
1, 'foo', 100, 2010-06-29 09:00, 2010-06-29 09:05
2, 'foo', 200, 2010-06-29 09:05, None

`x` used to correspond to the row with id of 1, but now corresponds to the row 
with the id of 2. That's the effect I'm looking to achieve.

I've added that recipe here 
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/VersionedRows

Sweet. A few questions:

- why do we need to refresh self.id in case it has expired? Doesn't the very next line(s) get rid of self.id?

- if the implementation of new_version was generic, I'm guessing we could live without the mixin?

- I take it there are no problems with specifying multiple extensions to sessionmaker? (we need zope.sqlalchemy's extension too) What effect does order of extensions have?

- why do we ignore instance states without an identity in before_flush?

- only primary objects in one table

that's not what your example above illustrates....

Well, I guess I meant there's only one table for each mapped class and there's only one active row per instance in the table at any one time. (I'd like to validate the latter, since users will be able to optionally set valid_from and valid_to; is before_flush the right place? Is session.query legit to use there? What exceptions are legit to raise from within before_flush to indicate validation failure?)

- the valid_from and valid_to form a linked list of version validity

using the recipe I linked, you'd establish that linkage in the new_version() 
method

Okay, and I guess I can use attributes.get_history(instance,'valid_from') and attributes.get_history(instance,'valid_to') to see if these attributes have been explicitly set?

Where is the History record returned by get_history documented?

- only certain column changes cause a new version to be created (eg: if the 
'notes' column changes, we don't want to create a new version; would  
session.is_modified() still help with that?)

using the recipe I linked, you'd add some logic into before_flush() that does 
attributes.get_history(x, 'foo') for each attribute that you care about, 
instead of using session.is_modified() which is across the board

Cool.

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
           - http://www.simplistix.co.uk

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

Reply via email to