0

I have two models A and B with an intermediary model C for holding a many-to-many relation using the through. as extra fields in C can have different values for the two same related objects of A and B, is it logically OK to do that? i.e. pair of foreign keys to (A, B) in C to be not unique (Django do not create unique_together on them)

pajooh
  • 1,916
  • 2
  • 18
  • 17

1 Answers1

1

It is possible for multiple relationships between two objects to exist in your through table. This can have surprising results when fetching related items, however, as a.b_set.all() will contain multiple copies of the item from B where there are multiple relationships. If this is not desired, then you can use a.b_set.all().distinct() to remove the duplicate items.

Kevin Christopher Henry
  • 46,175
  • 7
  • 116
  • 102
TimD
  • 1,371
  • 3
  • 12
  • 20