Ticket #15823: 15823.diff
File 15823.diff, 3.0 KB (added by , 14 years ago) |
---|
-
django/db/models/sql/query.py
452 452 # An unused alias. 453 453 continue 454 454 promote = (rhs.alias_map[alias][JOIN_TYPE] == self.LOUTER) 455 new_alias = self.join(rhs.rev_join_map[alias], 455 lhs, table, lhs_col, col = rhs.rev_join_map[alias] 456 # If the left side of the join was already relabeled, use the 457 # updated alias. 458 if lhs in change_map: 459 lhs = change_map[lhs] 460 new_alias = self.join((lhs, table, lhs_col, col), 456 461 (conjunction and not first), used, promote, not conjunction) 457 462 used.add(new_alias) 458 463 change_map[alias] = new_alias -
tests/regressiontests/null_fk/tests.py
1 1 from django.test import TestCase 2 from django.db.models import Q 2 3 3 4 from regressiontests.null_fk.models import * 4 5 … … 40 41 ], 41 42 transform = lambda c: (c.id, c.comment_text, repr(c.post)) 42 43 ) 44 45 def test_combine_isnull(self): 46 item = Item.objects.create(title='Some Item') 47 pv = PropertyValue.objects.create(label='Some Value') 48 item.props.create(key='a', value=pv) 49 item.props.create(key='b') # value=NULL 50 q1 = Q(props__key='a', props__value=pv) 51 q2 = Q(props__key='b', props__value__isnull=True) 52 53 # Each of these individually should return the item. 54 self.assertEqual(Item.objects.get(q1), item) 55 self.assertEqual(Item.objects.get(q2), item) 56 57 # Logically, qs1 and qs2, and qs3 and qs4 should be the same. 58 qs1 = Item.objects.filter(q1) & Item.objects.filter(q2) 59 qs2 = Item.objects.filter(q2) & Item.objects.filter(q1) 60 qs3 = Item.objects.filter(q1) | Item.objects.filter(q2) 61 qs4 = Item.objects.filter(q2) | Item.objects.filter(q1) 62 63 # Regression test for #15823. 64 self.assertEqual(list(qs1), list(qs2)) 65 self.assertEqual(list(qs3), list(qs4)) -
tests/regressiontests/null_fk/models.py
31 31 32 32 def __unicode__(self): 33 33 return self.comment_text 34 35 # Ticket 15823 36 37 class Item(models.Model): 38 title = models.CharField(max_length=100) 39 40 class PropertyValue(models.Model): 41 label = models.CharField(max_length=100) 42 43 class Property(models.Model): 44 item = models.ForeignKey(Item, related_name='props') 45 key = models.CharField(max_length=100) 46 value = models.ForeignKey(PropertyValue, null=True)