Hi Michael,
Thanks for replying so quickly!
On Wednesday, 28 October 2015 15:04:56 UTC, Michael Bayer wrote:
> OK, sorry, you've misunderstood the documentation. When it says
> "delete", it refers to the *parent* object that refers to the *child*,
> that is, the parent is the one that the foreign key refers *to*, and the
> child is the one that has a foreign key reference to the parent. This
> is the opposite case. You're deleting one of the objects that
> references the parent, that does not inherently affect the parent until
> it is freshly re-loaded from the database, such as after a commit.
>
I think some of my examples do do that (or try to). For example:
session.delete(flat)
session.flush()
debug("muffin.id_house is None", muffin.id_house is None, muffin.id_house,
None)
debug("muffin.house is None", muffin.house is None, muffin.house, None)
In this case, muffin has a foreign key to flat, which we delete.
muffin.id_house is set to None (correctly) but muffin.house is not (I was
hoping it would be).
Also, in the case of a many-to-many relationship (Cat and House), which is
the parent object and which is the child?
This is why it's better to deal with manipulation of the collection,
> instead of using session.delete(). See the section
>
> http://docs.sqlalchemy.org/en/rel_1_0/orm/session_basics.html#deleting-from-collections.
>
>
>
OK, I hadn't thought of that, it might work but in fact I want to delete a
Cat when it has no Houses left (House -> Cat in this case, with
uselist=True instead of uselist=False as in the example above) and it's not
clear that delete-orphan can reliably do this to the "one" side of the
relationship, can it? The documentation seems to imply not:
delete-orphan cascade implies that each child object can only have one
> parent at a time,
So there isn't an existing mechanism other than session.delete() that I can
see, am I missing something?
Thanks, Chris.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.