On Sep 21, 2010, at 12:19 PM, bipo wrote: > Hello, > > I have a problem with the MapperExtension. In the method > "before_update" i want to create a new object, add it to the session > and attach it to the object i'm updating, but it doesn't work. In the > documentation i've read that we can't modify the session plan in the > mapperExtension, so how could i do that ?
use SessionExtension.before_flush(). http://www.sqlalchemy.org/docs/orm/interfaces.html?highlight=before_insert#sqlalchemy.orm.interfaces.SessionExtension.before_flush an example: http://www.sqlalchemy.org/trac/wiki/UsageRecipes/VersionedRows > > Example : > > class CityExtension(MapperExtension): > def before_update(self,mapper, connection, instance): > .... > instance.location.address = 'XXXX' => this is not committed > > Class City: > __mapper_args__ = {'extension': CityExtension()} > location = orm.relation(Location,...) > ... > > Class Location: > name > address > ... > > Please help, how can i succeed ? > > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@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. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.