#33209: ManyToManyField.add() doesn't respect a unique constraint in 
intermediate
table
-------------------------------------+-------------------------------------
     Reporter:  Yuta Okamoto         |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  3.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 I'll let others chime in but I think this is invalid.

 `ManyToManyField` was designed to allow only a single instance of the
 relationship it defines and not allow extra dimensions to be considered.
 In your case that means a single instance of the `Member <-> Company`
 many-to-many relationship can be tracked at a time and the `role`
 dimension is not taken into account at all.

 If you want to keep using `ManyToManyField` for this purpose you'll likely
 need to tweak your data model a bit

 e.g.

 {{{#!python
 class Company(models.Model):
     pass

 class Role(models.Model):
     company = models.ForeignKey(Company, related_name='roles')

 class Member(models.Model):
     roles = models.ManyToManyField(Role, related_name='members')

    @property
    def companies(self):
        return Company.objects.filter(roles__members=self)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33209#comment:6>
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/065.64b9955b478ec36b32e2dce310ce3da7%40djangoproject.com.

Reply via email to