diff --git a/tests/regressiontests/select_related_onetoone/models.py b/tests/regressiontests/select_related_onetoone/models.py
index 3d6da9b..1be9eb8 100644
a
|
b
|
class Image(models.Model):
|
52 | 52 | class Product(models.Model): |
53 | 53 | name = models.CharField(max_length=100) |
54 | 54 | image = models.OneToOneField(Image, null=True) |
| 55 | |
| 56 | |
| 57 | class UserChild(User): |
| 58 | pass |
diff --git a/tests/regressiontests/select_related_onetoone/tests.py b/tests/regressiontests/select_related_onetoone/tests.py
index 4ccb584..26d76fa 100644
a
|
b
|
from django.conf import settings
|
3 | 3 | from django.test import TestCase |
4 | 4 | |
5 | 5 | from models import (User, UserProfile, UserStat, UserStatResult, StatDetails, |
6 | | AdvancedUserStat, Image, Product) |
| 6 | AdvancedUserStat, Image, Product, UserChild) |
7 | 7 | |
8 | 8 | class ReverseSelectRelatedTestCase(TestCase): |
9 | 9 | def setUp(self): |
… |
… |
class ReverseSelectRelatedTestCase(TestCase):
|
92 | 92 | p2 = Product.objects.create(name="Talking Django Plushie") |
93 | 93 | |
94 | 94 | self.assertEqual(len(Product.objects.select_related("image")), 2) |
| 95 | |
| 96 | def test_select_related_with_inheritance(self): |
| 97 | """ |
| 98 | select_related should not pre-fill the SingleRelatedObjectDescriptor |
| 99 | cache with None when the related object does not exist. |
| 100 | |
| 101 | This tests both the inheritance and the standard OneToOneField usage |
| 102 | case. |
| 103 | """ |
| 104 | User.objects.create() |
| 105 | user = User.objects.all()[0] |
| 106 | |
| 107 | self.assertRaises(UserChild.DoesNotExist, lambda: user.userchild) |
| 108 | self.assertRaises(UserProfile.DoesNotExist, lambda: user.userprofile) |
| 109 | |
| 110 | user = User.objects.all().select_related('userchild', 'userprofile')[0] |
| 111 | self.assertRaises(UserChild.DoesNotExist, lambda: user.userchild) |
| 112 | self.assertRaises(UserProfile.DoesNotExist, lambda: user.userprofile) |