Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2653 closed defect (fixed)

multiple manytomanyfield on self causes complaint in manage.py

Reported by: shaleh@… Owned by: russellm
Component: Core (Other) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Consider:

class Foo(models.Model):
     related = models.ManyToManyField('self')
     suggestions = models.ManyToManyField('self')

Both relations should be symmetrical. If A suggests B, B suggests A (for this code
base anyways).

What I expected to happen is adding B to A would add A to B. Instead I get:

app.foo: Accessor for m2m field 'menu_suggestions' clashes with related
m2m field 'Foo.foo_set'. Add a related_name argument to the definition
for 'suggestions'.
app.foo: Accessor for m2m field 'related' clashes with related m2m field
'Foo.foo_set'. Add a related_name argument to the definition for 'related'.

Doesn't matter whether I set symmetrical to false or true.

The confusion stems from model-api.txt which states:

``symmetrical`` Only used in the definition of ManyToManyFields on self.
                 Consider the following model:
                        class Person(models.Model):
                             friends = models.ManyToManyField("self")
  	
              When Django processes this model, it identifies that it has
              a ``ManyToManyField`` on itself, and as a result, it
              doesn't add a ``person_set`` attribute to the ``Person``
              class. Instead, the ``ManyToManyField`` is assumed to be
              symmetrical -- that is, if I am your friend, then you are
              my friend.
	
              If you do not want symmetry in ``ManyToMany`` relationships
              with ``self``, set ``symmetrical`` to ``False``. This will
              force Django to add the descriptor for the reverse
              relationship, allowing ``ManyToMany`` relationships to be
              non-symmetrical.

Attachments (0)

Change History (4)

comment:1 Changed 8 years ago by russellm

  • Owner changed from adrian to russellm

comment:2 Changed 8 years ago by russellm

  • Status changed from new to assigned

comment:3 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [3734]) Fixes #2653 -- Modified related field utility methods to return None as the related name for symmetrical m2m fields on self. Updated validators and unit tests to account for the new behavior.

comment:4 Changed 8 years ago by shaleh@…

This does indeed resolve the issue. Thanks.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.