Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build/
dist/
docs/_build/
htmlcov/
venv/
19 changes: 19 additions & 0 deletions polymorphic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ class DateModel(PolymorphicModel):
date = models.DateTimeField()


class PrefetchRelatedA(PolymorphicModel):
pass


class PrefetchRelatedB(models.Model):
links = models.ManyToManyField(PrefetchRelatedA)


class PolymorphicTests(TestCase):
"""
The test suite
Expand Down Expand Up @@ -1325,6 +1333,17 @@ def func():
# Ensure no queries are made using the default database.
self.assertNumQueries(0, func)

def test_prefetch_related_behaves_normally_with_polymorphic_model(self):
"""See #68"""
b1 = PrefetchRelatedB.objects.create()
b2 = PrefetchRelatedB.objects.create()
a = b1.links.create()
b2.links.add(a)

qs = PrefetchRelatedB.objects.prefetch_related('links')
for obj in qs:
self.assertEqual(len(obj.links.all()), 1)


def qrepr(data):
"""
Expand Down