mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Fixed #30368 -- Fixed prefetch_related() for GenericForeignKey when PK is also a FK.
This commit is contained in:
parent
d610521bff
commit
a4055adf70
3 changed files with 11 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue