On Jan 8, 2008, at 3:01 AM, Andrzej wrote:
> > Hi, > > is this possible to override the behaviour of DELETE statement in > ORM? I would like to update the table column instead of delete the > row in case the object will be deleted (something like T.remove_date = > timestamp). > > I know, there is a MapperExtension, but this - as I could see - allows > me only to hook into 'before' and 'after' places within the process of > deletion (Mapper._delete_obj) but does not prevent deletion of the > row. > I dont think that approach is advisable and you're probably better off not using session.delete() if you dont actually want something to be deleted- you should make your own delete() function which issues the timestamp change and whatever other dereferencing is needed (and no actual session.delete()) if thats what you want. For one thing, if you have an object A referenced by B as a parent, and a delete of B is superceded by an update of just a timestamp, now B still has the foreign key linking to A and will still show up as one of its children. If you want to try doing just what you describe, issue the UPDATE statement in the before_delete() mapper hook, and then remove the "_instance_key" attribute from the instance using "del obj._instance_key"; that should suppress the actual DELETE from occurring. but removing "_instance_key" as a way of doing this is not guaranteed to stay that way in future releases. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
