> -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Randall Nortman > Sent: 22 September 2009 16:31 > To: sqlalchemy > Subject: [sqlalchemy] Pre-commit validation spanning multiple > tables/ORM classes >
[SNIP] > > So if I do this with a SessionExtension.before_commit(), I would have > to iterate through the new, dirty, and deleted instances lists, > inspect the type of each instance, and do whatever is required. I am > not sure, though, how to handle the case of a change in membership in > the parent/child relationship -- the child instance that is present in > the dirty list will have only the new parent on it -- how do I find > out what the old parent was, so I can validate it? If a flush has > already occurred, the old value is already lost in the context of the > current transaction, and I think that if I open a new transaction > inside a before_commit() validator I'm just asking for trouble. Do I > need to instrument the Child class with a descriptor that tracks > changes to the parent and remembers the old parent? Or can I set the > cascade option in such a way that the old parent will end up in the > dirty list, even though there are no changes to its underlying table, > and in fact it may never have been explicitly loaded into the > session? (I must admit to be somewhat unsure of what the different > cascade options do -- but they don't seem to be useful for tracking > something like this.) > I can't answer most of your question, but as far as finding out what the old parent was, could you use the get_history function? <http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html#sqlalchemy .orm.attributes.get_history> Hope that helps, Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
