[sqlalchemy] onupdate Column attribute with joined table inheritance question

2009-03-02 Thread John Fries
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=gstq=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?

Any advice would be extremely appreciated.

Thanks,
John

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] onupdate Column attribute with joined table inheritance question

2008-09-02 Thread Sam Magister

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())

The rational is so I could keep track of when any employees info is
changed, be it a manager or engineer.

However, this field is not being updated when an engineer or manager
is updated. I'm pretty sure I understand why: The employee table is
not being updated.

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.

Thanks!

Sam
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---