--
Ticket URL: <https://code.djangoproject.com/ticket/17461>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 1
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
This is true specifically for asymmetric M2M's using an intermediate
model; it's an implementation detail coded into the accessor calls here:
https://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L1135
and a little lower down, here:
https://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L1154
It's worth noting that this the case in the docs, probably under the
"symmetrical" section of the docs here:
https://docs.djangoproject.com/en/1.3/ref/models/fields/#django.db.models.ManyToManyField.symmetrical
--
Ticket URL: <https://code.djangoproject.com/ticket/17461#comment:1>
* owner: nobody => Oxylo
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/17461#comment:2>
Comment (by Oxylo):
Confirmed today on master that Django still determines the 'from field'
and the 'to field' by its definition order in this case. We proved this by
comparing the SQL generated for both orderings of the fields "target" and
"follower"
When the field "target" is above the field "follower"
u1 = User.objects.create(name="Erik")
print u1.followers.all().query
returns the desired SQL:
SELECT "testm2m_user"."id", "testm2m_user"."name"
FROM "testm2m_user" INNER JOIN "testm2m_relationship"
ON ( "testm2m_user"."id" = "testm2m_relationship"."follower_id" )
WHERE "testm2m_relationship"."target_id" = 1
but if the field "follower" is above the field "target" the following
(incorrect) SQL is returned:
SELECT "testm2m_user"."id", "testm2m_user"."name"
FROM "testm2m_user" INNER JOIN "testm2m_relationship"
ON ( "testm2m_user"."id" = "testm2m_relationship"."target_id" )
WHERE "testm2m_relationship"."follower_id" = 1
Conclusion:
This issue still persists and needs to be documented accordingly.
--
Ticket URL: <https://code.djangoproject.com/ticket/17461#comment:3>