#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: | no | UI/UX: | no |
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.
Note:
See TracTickets
for help on using tickets.
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.