Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#12641 closed (invalid)

ManyToMany relationship with self, symmetrical=True, related_name='something' doesn't work

Reported by: hwmrocker Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

 class Tag(models.Model): 
    text = models.CharField(max_length=200) 
    children = models.ManyToManyField('self', blank=True, null=True, symmetrical=True, related_name='parents') 
    synonyms = models.ManyToManyField('self', blank=True, null=True)


When I do this I cannot check the parents of an object, since there is no Property created. When I try to use the related_name with an relationship to an other object than self everything works fine.

What I want is a symmetrical link to the same object, like a linked
list with the difference that these is a many to many relationship.
Since there is also something like synonyms treebear and mptt are not
usefull for me.

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

That's because a symmetrical m2m with self doesn't use the related_name.

The reason for this becomes obvious if you look at the data being stored. In the case of parent/child, the relationship isn't symmetrical - if A is a child of B, it doesn't follow that A is a parent of B.

In contrast, "friend" is a symmetrical m2m relationship - if I am your friend, then you are my friend.

comment:2 Changed 4 years ago by hwmrocker

thanks for your clarification, and sorry for the invalid report

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.