diff --git a/tests/regressiontests/select_related_regress/models.py b/tests/regressiontests/select_related_regress/models.py
index a291a54..c6d4e1c 100644
a
|
b
|
class Item(models.Model):
|
94 | 94 | |
95 | 95 | def __str__(self): |
96 | 96 | return self.name |
| 97 | |
| 98 | class ChildA(models.Model): |
| 99 | parent = models.ForeignKey(Parent) |
| 100 | |
| 101 | @python_2_unicode_compatible |
| 102 | class ChildB(models.Model): |
| 103 | name = models.CharField(max_length=10) |
| 104 | parent = models.ForeignKey(Parent, null=True) |
| 105 | child = models.ForeignKey(ChildA, null=True) |
| 106 | |
| 107 | def __str__(self): |
| 108 | return self.name |
diff --git a/tests/regressiontests/select_related_regress/tests.py b/tests/regressiontests/select_related_regress/tests.py
index 0e27d07..47ef0ef 100644
a
|
b
|
|
1 | 1 | from __future__ import absolute_import, unicode_literals |
2 | 2 | |
| 3 | from django.db import models |
3 | 4 | from django.test import TestCase |
4 | 5 | from django.utils import six |
5 | 6 | |
6 | 7 | from .models import (Building, Child, Device, Port, Item, Country, Connection, |
7 | 8 | ClientStatus, State, Client, SpecialClient, TUser, Person, Student, |
8 | | Organizer, Class, Enrollment) |
| 9 | Organizer, Class, Enrollment, Parent, ChildA, ChildB) |
9 | 10 | |
10 | 11 | |
11 | 12 | class SelectRelatedRegressTests(TestCase): |
… |
… |
class SelectRelatedRegressTests(TestCase):
|
162 | 163 | # The select_related join was promoted as there is already an |
163 | 164 | # existing join. |
164 | 165 | self.assertTrue('LEFT OUTER' in str(qs.query)) |
| 166 | |
| 167 | def test_ticket_20528(self): |
| 168 | """ |
| 169 | Regression for #20528 |
| 170 | |
| 171 | Using Qs and select_related with a certain config of ForeignKeys |
| 172 | resulted in incorrect joins. |
| 173 | """ |
| 174 | parent = Parent.objects.create(name="foo") |
| 175 | childA = ChildA.objects.create(parent=parent) |
| 176 | childB = ChildB.objects.create(child=childA, name="Bobby") |
| 177 | queryset = ChildB.objects.filter( |
| 178 | models.Q(parent=parent) | models.Q(child__parent=parent) |
| 179 | ) |
| 180 | expected_queryset = ['<ChildB: Bobby>'] |
| 181 | # this always works |
| 182 | self.assertQuerysetEqual(queryset, expected_queryset) |
| 183 | |
| 184 | # this started failing after 3fef304ff237fe692459c1f5b840acf7886c50bb |
| 185 | queryset = queryset.select_related('parent') |
| 186 | import sys |
| 187 | sys.stderr.write(str(queryset.query)) |
| 188 | self.assertQuerysetEqual(queryset, expected_queryset) |