views:

27

answers:

1

If I have two classes A and B with a many to many relationship and I want to delete an instance of A, do I need to remove all of its related Bs first or will Django sort that out for me?

I obviously don't want to leave orphaned rows in the join table.

Does it make any difference if the ManyToMany field is declared on class A or B?

Does it make any difference if there are additional fields on a join class specified using the "through" parameter?

+1  A: 

If I have two classes A and B with a many to many relationship and I want to delete an instance of A, do I need to remove all of its related Bs first or will Django sort that out for me?

Short answer: Django will sort that out for you.

Does it make any difference if the ManyToMany field is declared on class A or B?

As far as I know, no, it does not make a difference.

Does it make any difference if there are additional fields on a join class specified using the "through" parameter?

I haven't tried this myself but I don't see why there should be a problem.

Manoj Govindan