You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, if you want a ManyToMany relation for friends and you want the logic to be "if I am your friend, then you are my friend", you would use a symmetrical relation. That way, there is no related attribute generated on the other class, and for checking the friend status, you only have to look up one field instead of both.
The example you linked shows recursdive relations, but they're not symmetrical. talks_to and gets_talked_to are two different sets despite being the same relation, if it's symmetrical then both sets should be identical.
Once again, I like the example of "If X is my friend, then I am the friend of X". If talks_to was symmetrical, this would work:
>>>await_1.talks_to.add(_2, _1_1_1, loose)
>>>await_1.talks_to.all()
[<Employee: 4>, <Employee: 6>, <Employee: 2>]
>>>await_2.talks_to.all() # right now this returns an empty list
[<Employee: 3>]
Django ORM has support for what they call symmetrical relationships, that is a
ManyToMany
relationship on self. (see here https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyField.symmetrical)For example, if you want a ManyToMany relation for friends and you want the logic to be "if I am your friend, then you are my friend", you would use a symmetrical relation. That way, there is no related attribute generated on the other class, and for checking the friend status, you only have to look up one field instead of both.
Example
I can try to contribute this, but I want the confirmation from a maintainer first
The text was updated successfully, but these errors were encountered: