On Jul 21, 3:35 pm, Conor <conor.edward.da...@gmail.com> wrote:
>
> It means that there is a Child row already in the database with
> parent_id=1234. When you reassign p.children to not include that child,
> SQLAlchemy detects that the child object is now an orphan (has no
> parent). Based on your cascade rules (cascade="all"), SQLAlchemy will
> try to NOT delete the child, but instead set its parent_id to NULL (the
> only sensible alternative to not deleting the child).
>
> If you want the child to be deleted in this case, change the cascade to
> "all,delete-orphan". Otherwise, you need to ensure that the child is
> kept in p.children, e.g. p.children += [Child(details=x) for x in x_list].

Aah, thank you. That appears to have been exactly the problem. It's
hard to find many examples of working with objects like this in the
docs so I wasn't sure how to delete the old list and replace it with a
new list. It looks like the cascade="all,delete-orphan" is the right
thing to do for all ownership relations.

--
Ben Sizer

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

Reply via email to