On Jun 18, 2009, at 1:47 PM, Alberto Granzotto wrote:
> > > > On 18 Giu, 15:38, Michael Bayer <mike...@zzzcomputing.com> wrote: >> On Jun 18, 2009, at 6:03 AM, Alberto Granzotto wrote: >> >> >> >>> Hi, >>> I'm using sqlalchemy 0.4.8 and I'm looking for a safe deletion >>> extension (if exists one). >>> With "safe deletion" I mean to mark a record as deleted, not to >>> physically delete it, for example there is an extension for RoR >>> called >>> "acts as paranoid"[1]. >>> This extension add a "deleted_at" field to the model and: >>> 1. when you delete a record "deleted_at" is set to the current >>> timestamp; >> >> you can do this via myobject.deleted_at=func.now(), then flush > > but this doesn't propagate on all the children objects, I'd like to > mark them as "deleted" too. > I need to manually iterate through that is true, feel free to use the "cascade_iterator" mapper function (requires that "delete" cascade is configured on the relation()s you want to have this sort of cascade) : from sqlalchemy.orm.attributes import instance_state from sqlalchemy.orm import class_mapper def delete_obj(myobject): myobject.deleted_at = func.now() mapper = class_mapper(myobject) for obj, m in mapper.cascade_iterator("delete", instance_state(myobject)): obj.deleted_at = func.now() --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---