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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user