Also note that I have tried this variation of code as well, using 
secondary=<MAPPING_TABLE>, with the same result:

http://paste.openstack.org/show/63752/

-jay

On Sunday, February 9, 2014 10:45:55 PM UTC-5, Jay Pipes wrote:
>
> Hi all,
>
> I have some models with the following relationship:
>
> An Organization can have many Groups
> A Group belongs to one Organization
> A User can belong to many Groups
> A Group can have many Users
>
> I use a mapping model called UserGroupMembership that stores the user_id, 
> group_id relation of the many-to-many user to groups relationship.
>
> I cannot seem to get cascading deletes to work properly for the mapping 
> table.
>
> If I create an organization, a group under that organization, a user, and 
> add a record to the mapping table relating the user to the group, I would 
> expect that deleting the organization would delete the group record, as 
> well as the records in the mapping table that correspond to the group.
>
> Unfortunately, what actually happens is that the organization is deleted, 
> along with the group record. But the mapping table records corresponding to 
> that group are not deleted -- leaving orphan records.
>
> Here is code that demonstrates this:
>
> http://paste.openstack.org/show/63736/
>
> If you place the above code into a file called manydelete.py and execute 
> it, you will see an assertion raised:
>
> $ python manydelete.py 
> Traceback (most recent call last):
>   File "manydelete.py", line 127, in <module>
>     assert len(recs) == 0
> AssertionError
>
> Note: In case anyone is wondering, the reason I use sess.commit() a number 
> of times is to emulate what my code is doing (in multiple processes hitting 
> the database in different API calls...)
>
> I'm wondering if I have set up the cascading bits or the relation()s 
> improperly? Any help would be most appreciated!
>
> Best,
> -jay
>

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