Django

Code

Changeset 7761

Show
Ignore:
Timestamp:
06/26/08 01:50:22 (5 months ago)
Author:
mtredinnick
Message:

Fixed #7181 -- when ordering by a potentially NULL field, use a left-outer join
so that the ordering doesn't accidentally restrict the result set.

(Ironically, one existing test actually showed this problem, but I was too
dumb to notice the result was incorrect.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/sql/query.py

    r7760 r7761  
    611611        col = target.column 
    612612 
     613        # Must use left outer joins for nullable fields. 
     614        for join in joins: 
     615            self.promote_alias(join) 
     616 
    613617        # If we get to this point and the field is a relation to another model, 
    614618        # append the default ordering for that model. 
  • django/trunk/tests/regressiontests/queries/models.py

    r7760 r7761  
    500500# ForeignKey) is legal, but the results might not make sense. That isn't 
    501501# Django's problem. Garbage in, garbage out. 
    502 >>> Item.objects.all().order_by('tags', 'id') 
     502>>> Item.objects.filter(tags__isnull=False).order_by('tags', 'id') 
    503503[<Item: one>, <Item: two>, <Item: one>, <Item: two>, <Item: four>] 
    504504 
     
    763763[<Tag: t1>, <Tag: t4>, <Tag: t5>] 
    764764 
     765Bug #7181 -- ordering by related tables should accomodate nullable fields (this 
     766test is a little tricky, since NULL ordering is database dependent. Instead, we 
     767just count the number of results). 
     768>>> len(Tag.objects.order_by('parent__name')) 
     7695 
     770 
    765771"""} 
    766772