diff options
author | 朱穆穆 <mumu.zhu@feat.com> | 2022-12-29 10:23:46 +0800 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-24 10:20:27 +0100 |
commit | d3c93cdc597e0efc2815111c04dd5a427432ed37 (patch) | |
tree | 3b09888fcf698f51ac25fb6d0838cda890901d25 /tests/known_related_objects | |
parent | ef85b6bf0bc5a8b194f0724cf5bbedbcee402b96 (diff) | |
download | django-d3c93cdc597e0efc2815111c04dd5a427432ed37.tar.gz |
Fixed #34227 -- Fixed QuerySet.select_related() with multi-level FilteredRelation.
Diffstat (limited to 'tests/known_related_objects')
-rw-r--r-- | tests/known_related_objects/tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/known_related_objects/tests.py b/tests/known_related_objects/tests.py index 6080da3838..371c73d395 100644 --- a/tests/known_related_objects/tests.py +++ b/tests/known_related_objects/tests.py @@ -164,3 +164,23 @@ class ExistingRelatedInstancesTests(TestCase): ) self.assertIs(ps[0], ps[0].pool_1.poolstyle) self.assertIs(ps[0], ps[0].pool_2.another_style) + + def test_multilevel_reverse_fk_cyclic_select_related(self): + with self.assertNumQueries(3): + p = list( + PoolStyle.objects.annotate( + tournament_pool=FilteredRelation("pool__tournament__pool"), + ).select_related("tournament_pool", "tournament_pool__tournament") + ) + self.assertEqual(p[0].tournament_pool.tournament, p[0].pool.tournament) + + def test_multilevel_reverse_fk_select_related(self): + with self.assertNumQueries(2): + p = list( + Tournament.objects.filter(id=self.t2.id) + .annotate( + style=FilteredRelation("pool__another_style"), + ) + .select_related("style") + ) + self.assertEqual(p[0].style.another_pool, self.p3) |