Code

Ticket #17886: louter.diff

File louter.diff, 4.3 KB (added by milosu, 2 years ago)
Line 
1diff -ruN -x settings.py -x '*.pyc' -x '*.stackdump' -x '*.orig' -x '*.rej' ../Django-1.4c1.orig/django/db/models/sql/query.py ../Django-1.4c1/django/db/models/sql/query.py
2--- ../Django-1.4c1.orig/django/db/models/sql/query.py  2012-03-05 18:30:59.000000000 +0100
3+++ ../Django-1.4c1/django/db/models/sql/query.py       2012-03-12 22:13:35.591785300 +0100
4@@ -913,7 +913,10 @@
5             # Not all tables need to be joined to anything. No join type
6             # means the later columns are ignored.
7             join_type = None
8-        elif promote or outer_if_first:
9+        elif promote or outer_if_first or \
10+         self.alias_map[connection[0]][JOIN_TYPE] == self.LOUTER:
11+            # if preceeding alias (connection[0]) has LEFT OUTER JOIN
12+            # we should promote it
13             join_type = self.LOUTER
14         else:
15             join_type = self.INNER
16diff -ruN -x settings.py -x '*.pyc' -x '*.stackdump' -x '*.orig' -x '*.rej' ../Django-1.4c1.orig/tests/regressiontests/queries/models.py ../Django-1.4c1/tests/regressiontests/queries/models.py
17--- ../Django-1.4c1.orig/tests/regressiontests/queries/models.py        2012-03-05 18:30:57.000000000 +0100
18+++ ../Django-1.4c1/tests/regressiontests/queries/models.py     2012-03-12 22:11:59.575184600 +0100
19@@ -346,3 +346,16 @@
20 
21     def __unicode__(self):
22         return "one2one " + self.new_name
23+
24+class DefinitionOfDoubleCategorizedObject(models.Model):
25+    name = models.CharField(max_length=50)
26+
27+class CategorizedObject(models.Model):
28+    name = models.CharField(max_length=50)
29+    category = models.ForeignKey(SimpleCategory)
30+
31+class DoubleCategorizedObject(models.Model):
32+    name = models.CharField(max_length=50)
33+    rel_a = models.ForeignKey(CategorizedObject, null=True, blank=True, related_name="rel_a_double")
34+    rel_b = models.ManyToManyField(CategorizedObject, null=True, blank=True, related_name="rel_b_double")
35+    definition = models.ForeignKey(DefinitionOfDoubleCategorizedObject)
36diff -ruN -x settings.py -x '*.pyc' -x '*.stackdump' -x '*.orig' -x '*.rej' ../Django-1.4c1.orig/tests/regressiontests/queries/tests.py ../Django-1.4c1/tests/regressiontests/queries/tests.py
37--- ../Django-1.4c1.orig/tests/regressiontests/queries/tests.py 2012-03-05 18:30:57.000000000 +0100
38+++ ../Django-1.4c1/tests/regressiontests/queries/tests.py      2012-03-12 22:14:21.974423100 +0100
39@@ -3,6 +3,7 @@
40 import datetime
41 import pickle
42 import sys
43+import operator
44 
45 from django.conf import settings
46 from django.core.exceptions import FieldError
47@@ -18,7 +19,8 @@
48     ManagedModel, Member, NamedCategory, Note, Number, Plaything, PointerA,
49     Ranking, Related, Report, ReservedName, Tag, TvChef, Valid, X, Food, Eaten,
50     Node, ObjectA, ObjectB, ObjectC, CategoryItem, SimpleCategory,
51-    SpecialCategory, OneToOneCategory)
52+    SpecialCategory, OneToOneCategory, DoubleCategorizedObject, CategorizedObject,
53+    DefinitionOfDoubleCategorizedObject)
54 
55 
56 class BaseQuerysetTest(TestCase):
57@@ -1894,3 +1896,31 @@
58             DumbCategory.objects.create()
59         except TypeError:
60             self.fail("Creation of an instance of a model with only the PK field shouldn't error out after bulk insert refactoring (#17056)")
61+
62+class Queries6Test(BaseQuerysetTest):
63+    def setUp(self):
64+        c1 = SimpleCategory.objects.create(name="category1")
65+        c2 = SimpleCategory.objects.create(name="category2")
66+       cat_obj1 = CategorizedObject.objects.create(category=c1, name='cat1')
67+       cat_obj2 = CategorizedObject.objects.create(category=c2, name='cat2')
68+       definition = DefinitionOfDoubleCategorizedObject()
69+       definition.name = 'test def'
70+       definition.save()
71+       double_cat_obj = DoubleCategorizedObject()
72+       double_cat_obj.name = "test obj"
73+       double_cat_obj.rel_a = cat_obj1
74+       double_cat_obj.definition = definition
75+       double_cat_obj.save()
76+    def test_or_query(self):
77+        search_query = 'test def'
78+        or_queries = [
79+               Q(name__contains= search_query),
80+               Q(doublecategorizedobject__rel_a__name__icontains= search_query),
81+               Q(doublecategorizedobject__rel_a__category__name__icontains = search_query),
82+               Q(doublecategorizedobject__rel_b__name__icontains= search_query),
83+               Q(doublecategorizedobject__rel_b__category__name__icontains = search_query),
84+       ]
85+       q_obj = reduce(operator.or_, or_queries)
86+       qset = DefinitionOfDoubleCategorizedObject.objects.filter(q_obj).select_related()
87+       self.assertTrue(len(qset) == 1)
88+       self.assertNotIn('INNER JOIN', str(qset.query))