#17461: Document presumed order of foreign keys on intermediate M2M model
--------------------------------------+------------------------------------
Reporter: flytwokites@… | Owner: Oxylo
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.3
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/079.8a6c9502fb846e41bc0f32d083cda7c8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.