Skip to content

Commit 5bab440

Browse files
committed
Add a test case which shows that select_related works when using tree queries
Refs #18
1 parent ea22c47 commit 5bab440

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/testapp/test_queries.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ def test_always_tree_query(self):
391391
assert obj.name == "Something"
392392
AlwaysTreeQueryModel.objects.all().delete()
393393

394+
def test_tree_query_select_related(self):
395+
AlwaysTreeQueryModel.objects.create(
396+
name="Nothing", category=AlwaysTreeQueryModelCategory.objects.create()
397+
)
398+
AlwaysTreeQueryModel.objects.create(
399+
name="Nothing", category=AlwaysTreeQueryModelCategory.objects.create()
400+
)
401+
402+
tc = TestCase()
403+
with tc.assertNumQueries(1):
404+
_read = [
405+
(obj, obj.category)
406+
for obj in AlwaysTreeQueryModel.objects.with_tree_fields().select_related(
407+
"category"
408+
)
409+
]
410+
394411
def test_always_tree_query_relations(self):
395412
c = AlwaysTreeQueryModelCategory.objects.create()
396413

0 commit comments

Comments
 (0)