Ticket #19870: select_related_regress.patch

File select_related_regress.patch, 1.8 KB (added by loic84, 12 years ago)
  • tests/regressiontests/select_related_regress/models.py

    diff --git a/tests/regressiontests/select_related_regress/models.py b/tests/regressiontests/select_related_regress/models.py
    index a291a54..620b8eb 100644
    a b class Item(models.Model):  
    9494
    9595    def __str__(self):
    9696        return self.name
     97
     98# Models for testing bug #19870.
     99@python_2_unicode_compatible
     100class Fowl(models.Model):
     101    name = models.CharField(max_length=10)
     102
     103    def __str__(self):
     104        return self.name
     105
     106class Hen(Fowl):
     107    pass
     108
     109class Chick(Fowl):
     110    mother = models.ForeignKey(Hen)
  • tests/regressiontests/select_related_regress/tests.py

    diff --git a/tests/regressiontests/select_related_regress/tests.py b/tests/regressiontests/select_related_regress/tests.py
    index 0e27d07..f6d21b2 100644
    a b from django.utils import six  
    55
    66from .models import (Building, Child, Device, Port, Item, Country, Connection,
    77    ClientStatus, State, Client, SpecialClient, TUser, Person, Student,
    8     Organizer, Class, Enrollment)
     8    Organizer, Class, Enrollment, Hen, Chick)
    99
    1010
    1111class SelectRelatedRegressTests(TestCase):
    class SelectRelatedRegressTests(TestCase):  
    162162            # The select_related join was promoted as there is already an
    163163            # existing join.
    164164            self.assertTrue('LEFT OUTER' in str(qs.query))
     165
     166    def test_regression_19870(self):
     167        """
     168        Regression for #19870
     169
     170        """
     171        hen = Hen.objects.create(name='Hen')
     172        chick = Chick.objects.create(name='Chick', mother=hen)
     173
     174        self.assertEqual(Chick.objects.all()[0].mother.name, 'Hen')
     175        self.assertEqual(Chick.objects.select_related()[0].mother.name, 'Hen')
Back to Top