diff options
author | Mike Hansen <mike@rover.com> | 2017-10-18 12:05:08 -0700 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2017-11-02 10:06:00 -0400 |
commit | 514b2c989a948e3c59bda0da0c9427acf643cf5b (patch) | |
tree | d2c8edcef82fa45e3de4e8e7253ad23b24051494 /tests/prefetch_related | |
parent | ef718a72b3db81d35a6c1273b1565b48dd867e90 (diff) | |
download | django-514b2c989a948e3c59bda0da0c9427acf643cf5b.tar.gz |
Fixed #28723 -- Fixed RelatedManager's prefetch_related() cache name.
Diffstat (limited to 'tests/prefetch_related')
-rw-r--r-- | tests/prefetch_related/tests.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 36d60ea1f4..adadfa33b2 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -2,7 +2,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.db import connection from django.db.models import Prefetch, QuerySet -from django.db.models.query import get_prefetcher +from django.db.models.query import get_prefetcher, prefetch_related_objects from django.test import TestCase, override_settings from django.test.utils import CaptureQueriesContext @@ -1329,6 +1329,8 @@ class DirectPrefechedObjectCacheReuseTests(TestCase): AuthorAddress.objects.create(author=cls.author12, address='Haunted house'), AuthorAddress.objects.create(author=cls.author21, address='Happy place'), ] + cls.bookwithyear1 = BookWithYear.objects.create(title='Poems', published_year=2010) + cls.bookreview1 = BookReview.objects.create(book=cls.bookwithyear1) def test_detect_is_fetched(self): """ @@ -1405,6 +1407,14 @@ class DirectPrefechedObjectCacheReuseTests(TestCase): self.assertEqual(book1.first_authors[1].happy_place, []) self.assertEqual(book2.first_authors[0].happy_place, [self.author2_address1]) + def test_prefetch_reverse_foreign_key(self): + with self.assertNumQueries(2): + bookwithyear1, = BookWithYear.objects.prefetch_related('bookreview_set') + with self.assertNumQueries(0): + self.assertCountEqual(bookwithyear1.bookreview_set.all(), [self.bookreview1]) + with self.assertNumQueries(0): + prefetch_related_objects([bookwithyear1], 'bookreview_set') + class ReadPrefetchedObjectsCacheTests(TestCase): @classmethod |