-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support symmetrical ManyToMany relationships #1612
Comments
Hi! I am not sure, but if understand correct - we already support that: You can see example at Please write if I am wrong on what's issue |
Hi, thanks for your response! The example you linked shows recursdive relations, but they're not symmetrical. Once again, I like the example of "If X is my friend, then I am the friend of X". If >>> 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: