Thanks Michael! That should have been obvious to me, but for some reason I couldn't figure it out.
On Mon, Mar 2, 2009 at 11:24 AM, Michael Bayer <mike...@zzzcomputing.com>wrote: > > On Mar 2, 2009, at 2:16 PM, John Fries wrote: > > Hi all, > > I am having a problem that is identical to the one mentioned last year on > this list: > > http://groups.google.com/group/sqlalchemy/browse_thread/thread/efd3993c94c8d162/37943cda02151f2b?lnk=gst&q=onupdate+inheritance#37943cda02151f2b > > I have Engineer and Manager tables that are inheriting from an Employee > table using joined table inheritance. When I update one of the child > tables, I want the last_edited timestamp column on the Employee table to be > updated as well, but it is not updating. Mr. Bayer proposes the following: > > """ > 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. > """ > > I've done that step, but I don't understand what the next step is. I > thought that I would have to implement a __before_update__ method on my > Engineer and Manager classes, which would then call some method on Employee > using super. However, when I update my Engineer, it doesn't even look like > the __before_update__ method is being called. So I conclude that I'm doing > it wrong. Which instances should implement a __before_update__ method? > What should the __before_update__ method do? > > > just implement def __before_update__() on your base Employee class. this > method should set the last_edited attribute to a new value (note you can set > it to "func.now()" to have a SQL function fire off). Engineer and Manager > will have the method automatically via class inheritance. Also make sure > you are using the modfied mapper() function to create your mappers. > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---