#14056: Wrong query generated when using reverse foreign key
---------------------------------------------------+------------------------
Reporter: premalshah | Owner: nobody
Status: new | Milestone: 1.3
Component: Database layer (models, ORM) | Version: 1.0
Resolution: | Keywords: foreign key
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Comment (by anonymous):
I agree the current behavior is incorrect because:
{{{
SELECT `apptest_base`.`id`, `apptest_base`.`field1` FROM `apptest_base`
WHERE `apptest_base`.`id` = 1;
}}}
will return ALL Base objects with an id of 1, whereas:
{{{
SELECT `apptest_base`.`id`, `apptest_base`.`field1` FROM `apptest_base`
INNER JOIN `apptest_child`
ON (`apptest_base`.`id` = `apptest_child`.`obj_id`) WHERE
`apptest_child`.`obj_id` = 1;
}}}
will only return Base objects with an id of 1 who are referenced to by a
Child model, which is what 'Base.objects.filter(child__obj=1)' implies. So
a join is in fact required.
--
Ticket URL: <http://code.djangoproject.com/ticket/14056#comment:6>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.