Ticket #16715: wrong-join-test-r16910.patch
File wrong-join-test-r16910.patch, 3.3 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/model_inheritance_select_related/tests.py
2 2 3 3 from django.test import TestCase 4 4 5 from models import Restaurant, Person5 from models import Chain, Place, Restaurant, Franchise, FranchiseChainOptional, Person 6 6 7 7 8 8 class ModelInheritanceSelectRelatedTests(TestCase): … … 27 27 28 28 jane = Person.objects.order_by("name").select_related("favorite_restaurant")[0] 29 29 self.assertEqual(jane.favorite_restaurant.name, "Craft") 30 31 def test_select_related_foreign_key(self): 32 # Regression test for #16715 (1/2) 33 c = Chain.objects.create() 34 p = Place.objects.create(name="SomePlace") 35 f = Franchise.objects.create(name="SomeFranchise", chain=c) 36 37 self.assertEqual(len(Place.objects.all()), 2) 38 self.assertEqual(len(Place.objects.select_related("franchise")), 2) 39 # In 16715 the following query silently dropped the place that 40 # was not a franchise due to selecting an INNER JOIN instead 41 # of LEFT OUTER JOIN when joining the Franchise and Chain 42 # tables. 43 self.assertEqual(len(Place.objects.select_related("franchise__chain")), 2) 44 45 def test_select_related_foreign_key_null(self): 46 # Regression test for #16715 (2/2) 47 c = Chain.objects.create() 48 p = Place.objects.create(name="SomePlace") 49 f = FranchiseChainOptional.objects.create(name="SomeFranchise", chain=c) 50 51 self.assertEqual(len(Place.objects.all()), 2) 52 self.assertEqual(len(Place.objects.select_related("franchisechainoptional")), 2) 53 # In 16715 the following query works as expected as attribute 54 # null=True on the chain foreign key forces the join back to 55 # LEFT OUTER JOIN in any case. 56 self.assertEqual(len(Place.objects.select_related("franchisechainoptional__chain")), 2) -
tests/regressiontests/model_inheritance_select_related/models.py
5 5 6 6 from django.db import models 7 7 8 9 class Chain(models.Model): 10 pass 11 12 8 13 class Place(models.Model): 9 14 name = models.CharField(max_length=50) 10 15 … … 14 19 def __unicode__(self): 15 20 return u"%s the place" % self.name 16 21 22 17 23 class Restaurant(Place): 18 24 serves_sushi = models.BooleanField() 19 25 serves_steak = models.BooleanField() … … 21 27 def __unicode__(self): 22 28 return u"%s the restaurant" % self.name 23 29 30 31 class Franchise(Place): 32 chain = models.ForeignKey(Chain) 33 34 def __unicode__(self): 35 return u"%s the franchise" % self.name 36 37 class FranchiseChainOptional(Place): 38 chain = models.ForeignKey(Chain, null=True) 39 40 def __unicode__(self): 41 return u"%s the franchise (chain optional)" % self.name 42 43 24 44 class Person(models.Model): 25 45 name = models.CharField(max_length=50) 26 46 favorite_restaurant = models.ForeignKey(Restaurant)