Django

Code

Show
Ignore:
Timestamp:
04/24/08 11:07:07 (9 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Changed the way order_by() and distinct() interact.

When using "select distinct" all ordering columns must be part of the output
(select) columns. We were previously just throwing away ordering columns that
weren't included, but there are some cases where they are needed and it's
difficult to add them in manually. So now the default behaviour is to append
any missing columns.

This can affect the output of distinct() if complicated order_by() constructs
are used, so the documentation has been updated with an explanation of what's
going on there.

Fixed #7070.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/tests/modeltests/many_to_one/models.py

    r7230 r7455  
    251251[<Reporter: John Smith>] 
    252252 
    253 # It's possible to use values() calls across many-to-one relations. 
     253# It's possible to use values() calls across many-to-one relations. (Note, too, that we clear the ordering here so as not to drag the 'headline' field into the columns being used to determine uniqueness.) 
    254254>>> d = {'reporter__first_name': u'John', 'reporter__last_name': u'Smith'} 
    255 >>> list(Article.objects.filter(reporter=r).distinct().values('reporter__first_name', 'reporter__last_name')) == [d] 
     255>>> list(Article.objects.filter(reporter=r).distinct().order_by().values('reporter__first_name', 'reporter__last_name')) == [d] 
    256256True 
    257257