#34207: Incorrect SQL query when adding a ManyToMany related object with a
"through" table prevents adding a new relationship if the new relationship
is identical except for a different value for "through_defaults"
-------------------------------------+-------------------------------------
     Reporter:  Credentive           |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  duplicate
     Keywords:  ManyToManyField      |             Triage Stage:
  through                            |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 > Your example documentation strongly suggests otherwise

 Could you elaborate on that? From what I can read none of the examples you
 linked suggest that `add` supports this feature?

 There is effectively a section that points at the fact that
 `remove(related)` will remove all entries matching the `(from, to)` tuple
 but defined by the many-to-many

 In the example you've just provided you don't use `members.add` to add the
 second relationship to Ringo but rely on explicit `Membership` creation
 which is supported.

 To make it clear, intermediary models that don't define a strict unique
 relationship on `(from, to)` are supported. However
 `add(through_defaults)` is focused on enforcing that at least one entry of
 the `(from, to)` tuple exists and doesn't make any assumption with regards
 to the unique constraints defined on the intermediary model.

 If you want to enforce the unique existence of a tuple that is a superset
 of the the `(from, to)` relationship you should use `get_or_create`
 instead of expecting `add(through_defaults)` to figure out which of your
 unique constraints should be enforced based on your provided
 `through_defaults`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34207#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184fd40df1d-fecd7b51-9ea7-4ce1-8e39-d97b976c8ecc-000000%40eu-central-1.amazonses.com.

Reply via email to