On Sep 2, 2008, at 3:06 PM, Sam Magister wrote:
> > Hi, > > I'm using joined table inheritance much like the example given here: > http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_inheritance_joined > > Additionally, in the employees table, I would like an update_timestamp > column of type DateTime: > > Column('update_timestamp', DateTime, onupdate=datetime.datetime.now()) > Theres a common mistake here. Either have onupdate set to datetime.datetime.now (no parenthesis), or set it to func.now() to allow the database's own time function to be used. > I was just wondering if there was an easy way to get around this issue > without using MapperExtensions. Previously I was using > MapperExtensions and overriding the before_update method which works > since it looks for updates in the entire instance, not just that > table. This way works fine, but I like the cleanness of not needing > MapperExtensions. the MapperExtension approach can be made more clean by creating a generic one: from sqlalchemy.orm import mapper as _mapper from sqlalchemy.orm import MapperExtension class MyExt(MapperExtension): def before_update(self, mapper, connection, instance): if hasattr(instance, '__before_update__'): instance.__before_update__() def mapper(*args, **kw): kw['extension'] = MyExt() return _mapper(*args, **kw) just hide that code away someplace, and then any instance which defines a method called __before_update__() will have it called before update. A future release may include decorators which accomplish a similar result. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---