Re: [sqlalchemy] Cascade delete-orphan: reattach child to another parent

2018-03-31 Thread Serhii Mozghovyi
Many thanks! On Wednesday, March 28, 2018 at 6:42:16 PM UTC+3, Mike Bayer wrote: > > the backrefs intentionally don't keep fanning deep into object graph > for this kind of thing, so if you want it to go one hop further you > can add an event to do that directly: > > from sqlalchemy import

Re: [sqlalchemy] Cascade delete-orphan: reattach child to another parent

2018-03-28 Thread Mike Bayer
the backrefs intentionally don't keep fanning deep into object graph for this kind of thing, so if you want it to go one hop further you can add an event to do that directly: from sqlalchemy import event from sqlalchemy.orm import attributes @event.listens_for(Address.user, "set") def

[sqlalchemy] Cascade delete-orphan: reattach child to another parent

2018-03-28 Thread Serhii Mozghovyi
Is it possible to make child objects (many-to-one side) delete itself from the old parent's collection when it is added to a different parent? See the file attached. The old parent remains unaware that he doesn't have this child anymore. P.S. session.expire() is an obvious solution but too