1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #19500 -- Solved a regression in join reuse

The ORM didn't reuse joins for direct foreign key traversals when using
chained filters. For example:
    qs.filter(fk__somefield=1).filter(fk__somefield=2))
produced two joins.

As a bonus, reverse onetoone filters can now reuse joins correctly

The regression was caused by the join() method refactor in commit
68847135bc

Thanks for Simon Charette for spotting some issues with the first draft
of the patch.
This commit is contained in:
Anssi Kääriäinen
2012-12-20 21:25:48 +02:00
parent c04c03daa3
commit 3dcd435a0e
7 changed files with 65 additions and 32 deletions

View File

@@ -72,5 +72,11 @@ class GenericRelationTests(TestCase):
Q(notes__note__icontains=r'other note'))
self.assertTrue(org_contact in qs)
def test_join_reuse(self):
qs = Person.objects.filter(
addresses__street='foo'
).filter(
addresses__street='bar'
)
self.assertEqual(str(qs.query).count('JOIN'), 2)