Django

Code

Changeset 6867

Show
Ignore:
Timestamp:
12/03/07 15:10:51 (9 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Fixed query disjunctions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/sql/query.py

    r6866 r6867  
    99 
    1010import copy 
     11import operator 
    1112import re 
    1213 
     
    466467        for field in ordering: 
    467468            if field == '?': 
    468                 result.append(self.connector.ops.random_function_sql()) 
     469                result.append(self.connection.ops.random_function_sql()) 
    469470                continue 
    470471            if isinstance(field, int): 
     
    725726            self.promote_alias(join_list[-1][0]) 
    726727 
     728        if connector == OR: 
     729            # Some joins may need to be promoted when adding a new filter to a 
     730            # disjunction. We walk the list of new joins and where it diverges 
     731            # from any previous joins (ref count is 1 in the table list), we 
     732            # make the new additions (and any existing ones not used in the new 
     733            # join list) an outer join. 
     734            join_it = nested_iter(join_list) 
     735            table_it = iter(self.tables) 
     736            join_it.next(), table_it.next() 
     737            for join in join_it: 
     738                table = table_it.next() 
     739                if join == table and self.alias_map[join][ALIAS_REFCOUNT] > 1: 
     740                    continue 
     741                self.promote_alias(join) 
     742                if table != join: 
     743                    self.promote_alias(table) 
     744                break 
     745            for join in join_it: 
     746                self.promote_alias(join) 
     747            for table in table_it: 
     748                # Some of these will have been promoted from the join_list, but 
     749                # that's harmless. 
     750                self.promote_alias(table) 
     751 
    727752        self.where.add([alias, col, field, lookup_type, value], connector) 
     753 
    728754        if negate: 
    729755            flag = False 
     
    11991225        yield rows 
    12001226 
     1227def nested_iter(nested): 
     1228    """ 
     1229    An iterator over a sequence of sequences. Each element is returned in turn. 
     1230    Only handles one level of nesting, since that's all we need here. 
     1231    """ 
     1232    for seq in nested: 
     1233        for elt in seq: 
     1234            yield elt 
     1235 
    12011236def setup_join_cache(sender): 
    12021237    """ 
  • django/branches/queryset-refactor/tests/regressiontests/queries/models.py

    r6859 r6867  
    197197>>> Author.objects.filter(Q(name='a3') | Q(item__name='one')) 
    198198[<Author: a1>, <Author: a3>] 
     199>>> Author.objects.filter(Q(item__name='three') | Q(report__name='r3')) 
     200[<Author: a2>] 
    199201 
    200202Bug #6074