Yes, I meant that :P

I'll try with the before_flush_event.

Thanks!!

2012/3/21 Michael Bayer <[email protected]>

>
> On Mar 21, 2012, at 5:18 AM, Pau Tallada wrote:
>
> Hi!
>
> I have a model with a parent-child relationship on the same entity.
> The "children" collection on a parent instance has events set to intercept
> adding and removing instances to/from it. This is needed to update an
> attribute from the parent instance.
> But when I delete an instance which is the child of another one, that
> parent instance is not notified of its child removal and so the event is
> not fired.
>
> I tried working with the cascade rules but I have not been successful.
>
> Is this behaviour supported?
>
>
> "delete an instance", meaning,
>
> parent.children.append(child)
> session.delete(child)
> session.commit()
>
> ?
>
>
> in that case no, "parent.children" is not notified of a collection
> removal, since no collection alteration actually takes place.   The "child"
> is still there in parent.collection until the whole of "parent" is expired,
> which occurs after the commit().  See
> http://docs.sqlalchemy.org/en/latest/orm/session.html#deleting-from-collectionsfor
>  detailed discussion on this.
>
> Your two options here are to stick to collection mutations, or do an
> additional before_flush() or after_flush() event that goes through child
> objects marked deleted, finds their parents, and does what is needed.
>
>
>
>
> Thanks!
>
> Pau.
> --
> ----------------------------------
> Pau Tallada Crespí
> Dep. d'Astrofísica i Cosmologia
> Port d'Informació Científica (PIC)
> Tel: +34 93 586 8233
> ----------------------------------
>
>
>
> --
> 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.
>
>
>  --
> 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.
>



-- 
----------------------------------
Pau Tallada Crespí
Dep. d'Astrofísica i Cosmologia
Port d'Informació Científica (PIC)
Tel: +34 93 586 8233
----------------------------------

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

Reply via email to