On May 14, 2008, at 11:07 AM, Yannick Gingras wrote:
> > > Greetings Alchemists, > Is it possible to define a hook in a mapped class that will be called > to test the sanity of an instance before it gets committed? > > As an example: > > class Item(object): > def _pre_commit(self): > assert (self.dry_weight + self.fluids) < 50 > mapper(Item, items_table) > > I don't want to put the test mutators of dry_weight or fluids since > it's OK to have a temporary inconsistent state as long as the state is > consistent at commit time. > > I see that some of this functionality if covered by MapperExtention > but since the test is only related to Item I'd rather put the test in > it. > easy enough to build yourself a generic MapperExtension that scans incoming objects for a "_pre_commit()" method. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
