diff options
author | Vinny Do <vdo.code@gmail.com> | 2019-04-16 17:49:16 +1000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-04-16 09:49:16 +0200 |
commit | a4055adf702d086334a9ab2ca25a5e41e896a4fb (patch) | |
tree | 42dc2a71daf25b37169c8a0163c194659e7290ce /tests/prefetch_related | |
parent | d610521bffe9d44a070ebe3a719b474aff6d3d1e (diff) | |
download | django-a4055adf702d086334a9ab2ca25a5e41e896a4fb.tar.gz |
Fixed #30368 -- Fixed prefetch_related() for GenericForeignKey when PK is also a FK.
Diffstat (limited to 'tests/prefetch_related')
-rw-r--r-- | tests/prefetch_related/tests.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index a32ac81d12..0b3caed0dc 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -891,6 +891,13 @@ class GenericRelationTests(TestCase): qs = Comment.objects.prefetch_related('content_object_uuid') self.assertEqual([c.content_object_uuid for c in qs], [article]) + def test_prefetch_GFK_fk_pk(self): + book = Book.objects.create(title='Poems') + book_with_year = BookWithYear.objects.create(book=book, published_year=2019) + Comment.objects.create(comment='awesome', content_object=book_with_year) + qs = Comment.objects.prefetch_related('content_object') + self.assertEqual([c.content_object for c in qs], [book_with_year]) + def test_traverse_GFK(self): """ A 'content_object' can be traversed with prefetch_related() and |