1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #12937 -- Corrected the operation of select_related() when following an reverse relation on an inherited model. Thanks to subsume for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12814 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee
2010-03-20 15:02:59 +00:00
parent 4528f39886
commit bfa080f402
4 changed files with 41 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ from django import db
from django.conf import settings
from django.test import TestCase
from models import (User, UserProfile, UserStat, UserStatResult, StatDetails,
from models import (User, UserProfile, UserStat, UserStatResult, StatDetails,
AdvancedUserStat, Image, Product)
class ReverseSelectRelatedTestCase(TestCase):
@@ -22,7 +22,7 @@ class ReverseSelectRelatedTestCase(TestCase):
user2 = User.objects.create(username="bob")
results2 = UserStatResult.objects.create(results='moar results')
advstat = AdvancedUserStat.objects.create(user=user2, posts=200,
advstat = AdvancedUserStat.objects.create(user=user2, posts=200, karma=5,
results=results2)
StatDetails.objects.create(base_stats=advstat, comments=250)
@@ -74,18 +74,21 @@ class ReverseSelectRelatedTestCase(TestCase):
self.assertQueries(2)
def test_follow_from_child_class(self):
stat = AdvancedUserStat.objects.select_related("statdetails").get(posts=200)
stat = AdvancedUserStat.objects.select_related('user', 'statdetails').get(posts=200)
self.assertEqual(stat.statdetails.comments, 250)
self.assertEqual(stat.user.username, 'bob')
self.assertQueries(1)
def test_follow_inheritance(self):
stat = UserStat.objects.select_related('advanceduserstat').get(posts=200)
stat = UserStat.objects.select_related('user', 'advanceduserstat').get(posts=200)
self.assertEqual(stat.advanceduserstat.posts, 200)
self.assertEqual(stat.user.username, 'bob')
self.assertEqual(stat.advanceduserstat.user.username, 'bob')
self.assertQueries(1)
def test_nullable_relation(self):
im = Image.objects.create(name="imag1")
p1 = Product.objects.create(name="Django Plushie", image=im)
p2 = Product.objects.create(name="Talking Django Plushie")
self.assertEqual(len(Product.objects.select_related("image")), 2)