Changeset 8107
- Timestamp:
- 07/27/08 13:16:17 (4 months ago)
- Files:
-
- django/trunk/django/db/models/sql/query.py (modified) (1 diff)
- django/trunk/tests/regressiontests/queries/models.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/sql/query.py
r8053 r8107 1090 1090 table_it = iter(self.tables) 1091 1091 join_it.next(), table_it.next() 1092 table_promote = False 1092 1093 for join in join_it: 1093 1094 table = table_it.next() 1094 1095 if join == table and self.alias_refcount[join] > 1: 1095 1096 continue 1096 self.promote_alias(join)1097 join_promote = self.promote_alias(join) 1097 1098 if table != join: 1098 self.promote_alias(table)1099 table_promote = self.promote_alias(table) 1099 1100 break 1100 1101 for join in join_it: 1101 self.promote_alias(join) 1102 if self.promote_alias(join, join_promote): 1103 join_promote = True 1102 1104 for table in table_it: 1103 1105 # Some of these will have been promoted from the join_list, but 1104 1106 # that's harmless. 1105 self.promote_alias(table) 1107 if self.promote_alias(table, table_promote): 1108 table_promote = True 1106 1109 1107 1110 self.where.add((alias, col, field, lookup_type, value), connector) django/trunk/tests/regressiontests/queries/models.py
r8100 r8107 204 204 fan_of = models.ForeignKey(Celebrity) 205 205 206 # Multiple foreign keys 207 class LeafA(models.Model): 208 data = models.CharField(max_length=10) 209 210 def __unicode__(self): 211 return self.data 212 213 class LeafB(models.Model): 214 data = models.CharField(max_length=10) 215 216 class Join(models.Model): 217 a = models.ForeignKey(LeafA) 218 b = models.ForeignKey(LeafB) 206 219 207 220 __test__ = {'API_TESTS':""" … … 335 348 [<Number: 8>] 336 349 350 Bug #7872 351 Another variation on the disjunctive filtering theme. 352 353 # For the purposes of this regression test, it's important that there is no 354 # Join object releated to the LeafA we create. 355 >>> LeafA.objects.create(data='first') 356 <LeafA: first> 357 >>> LeafA.objects.filter(Q(data='first')|Q(join__b__data='second')) 358 [<LeafA: first>] 359 337 360 Bug #6074 338 361 Merging two empty result sets shouldn't leave a queryset with no constraints … … 431 454 True 432 455 433 Similarly, when one of the joins cannot possibly, ever, involve NULL values (Author -> ExtraInfo, in the following), it should never be promoted to a left outer join. So hte following query should only involve one "left outer" join (Author -> Item is 0-to-many).456 Similarly, when one of the joins cannot possibly, ever, involve NULL values (Author -> ExtraInfo, in the following), it should never be promoted to a left outer join. So the following query should only involve one "left outer" join (Author -> Item is 0-to-many). 434 457 >>> qs = Author.objects.filter(id=a1.id).filter(Q(extra__note=n1)|Q(item__note=n3)) 435 >>> len([x[2] for x in qs.query.alias_map.values() if x[2] == query.LOUTER ])458 >>> len([x[2] for x in qs.query.alias_map.values() if x[2] == query.LOUTER and qs.query.alias_refcount[x[1]]]) 436 459 1 437 460
