>
>
> you need to put a cascade rule on Page.user_relationships, such that when 
> you remove a Page_to_User from the collection, it’s marked as deleted, 
> instead of SQLAlchemy setting the page_id foreign key to NULL, which is 
> invalid here b.c. that column is part of the primary key (and hence the 
> error).   Page_to_User can’t exist in the database without being referred 
> to by a Page object since the primary key would be NULL.
>
> the delete-orphan cascade is introduced at:
>
>
> http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#configuring-delete-delete-orphan-cascade
>
> and some more information at: 
> http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#deleting-from-collections
>
>
>
Can you help me understand why a cascade rule is needed? I have read the 
documentation you linked to but still have trouble grasping why it is 
needed. I understand it would make sense if I deleted a page, that it 
should cascade on delete to page_to_user because now the FK page_id is no 
longer valid - the page doesn't exist, so it cannot possibly be mapped 
anywhere.

What I'm having trouble understanding is what is cascading from what to 
what when deleting from this page.user_relationships collection. It doesn't 
cascade from page, because I am not deleting any pages, and it doesn't 
cascade from users, because no users are deleted. The only thing being 
deleted is the mapping itself.

In the database table definition, there doesn't have to be any cascade 
settings at all for the constraints and it will still work fine. Maybe it's 
purely a SQLAlchemy thing and how it's designed for some reason? I would 
just like to understand better for future development. Thanks in advance.

-Russ

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to