mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #12885 -- Fixed queries with GenericRelations to multi-table inheritance child models.
This commit is contained in:
parent
4cd24bb67c
commit
cd0ba8053d
2 changed files with 45 additions and 2 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue