summaryrefslogtreecommitdiff
path: root/tests/generic_relations
diff options
context:
space:
mode:
authorAnssi Kääriäinen <anssi.kaariainen@thl.fi>2015-10-27 13:13:16 +0200
committerTim Graham <timograham@gmail.com>2015-12-14 10:48:01 -0500
commitcd0ba8053dfdc81ade9a656dc8049de600638501 (patch)
tree1e2a19940c9b82440bae8d7abcc6899f265a7f89 /tests/generic_relations
parent4cd24bb67c8d82630817e97ab9ba444ca955a94d (diff)
downloaddjango-cd0ba8053dfdc81ade9a656dc8049de600638501.tar.gz
Fixed #12885 -- Fixed queries with GenericRelations to multi-table inheritance child models.
Diffstat (limited to 'tests/generic_relations')
-rw-r--r--tests/generic_relations/tests.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py
index 3d3e2acfe5..1d3d3d373b 100644
--- a/tests/generic_relations/tests.py
+++ b/tests/generic_relations/tests.py
@@ -405,6 +405,13 @@ class GenericRelationsTests(TestCase):
# GenericRelations to models that use multi-table inheritance work.
granite = ValuableRock.objects.create(name='granite', hardness=5)
ValuableTaggedItem.objects.create(content_object=granite, tag="countertop", value=1)
+ self.assertEqual(ValuableRock.objects.filter(tags__value=1).count(), 1)
+ # We're generating a slightly inefficient query for tags__tag - we
+ # first join ValuableRock -> TaggedItem -> ValuableTaggedItem, and then
+ # we fetch tag by joining TaggedItem from ValuableTaggedItem. The last
+ # join isn't necessary, as TaggedItem <-> ValuableTaggedItem is a
+ # one-to-one join.
+ self.assertEqual(ValuableRock.objects.filter(tags__tag="countertop").count(), 1)
granite.delete() # deleting the rock should delete the related tag.
self.assertEqual(ValuableTaggedItem.objects.count(), 0)