Ticket #18014: 18014.diff

File 18014.diff, 3.2 KB (added by Anssi Kääriäinen, 12 years ago)
  • django/db/models/sql/query.py

    diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
    index ce11716..911872f 100644
    a b class Query(object):  
    104104        self.alias_map = {}     # Maps alias to join information
    105105        self.table_map = {}     # Maps table names to list of aliases.
    106106        self.join_map = {}
    107         self.rev_join_map = {}  # Reverse of join_map.
    108107        self.quote_cache = {}
    109108        self.default_cols = True
    110109        self.default_ordering = True
    class Query(object):  
    244243        obj.alias_map = self.alias_map.copy()
    245244        obj.table_map = self.table_map.copy()
    246245        obj.join_map = self.join_map.copy()
    247         obj.rev_join_map = self.rev_join_map.copy()
    248246        obj.quote_cache = {}
    249247        obj.default_cols = self.default_cols
    250248        obj.default_ordering = self.default_ordering
    class Query(object):  
    463461        change_map = {}
    464462        used = set()
    465463        conjunction = (connector == AND)
     464        # Add the joins in the rhs query into the new query.
    466465        first = True
    467466        for alias in rhs.tables:
    468467            if not rhs.alias_refcount[alias]:
    469468                # An unused alias.
    470469                continue
    471             promote = (rhs.alias_map[alias][JOIN_TYPE] == self.LOUTER)
    472             lhs, table, lhs_col, col = rhs.rev_join_map[alias]
     470            table, _, join_type, lhs, lhs_col, col, _ = rhs.alias_map[alias]
     471            promote = join_type == self.LOUTER
    473472            # If the left side of the join was already relabeled, use the
    474473            # updated alias.
    475474            lhs = change_map.get(lhs, lhs)
    476475            new_alias = self.join((lhs, table, lhs_col, col),
    477                     (conjunction and not first), used, promote, not conjunction)
     476                    conjunction and not first, used, promote, not conjunction)
    478477            used.add(new_alias)
    479478            change_map[alias] = new_alias
    480479            first = False
    class Query(object):  
    766765                    col.relabel_aliases(change_map)
    767766
    768767        # 2. Rename the alias in the internal table/alias datastructures.
     768        for k, aliases in self.join_map.items():
     769            aliases = tuple([change_map.get(a, a) for a in aliases])
     770            self.join_map[k] = aliases
    769771        for old_alias, new_alias in change_map.iteritems():
    770772            alias_data = list(self.alias_map[old_alias])
    771773            alias_data[RHS_ALIAS] = new_alias
    772 
    773             t = self.rev_join_map[old_alias]
    774             data = list(self.join_map[t])
    775             data[data.index(old_alias)] = new_alias
    776             self.join_map[t] = tuple(data)
    777             self.rev_join_map[new_alias] = t
    778             del self.rev_join_map[old_alias]
     774           
    779775            self.alias_refcount[new_alias] = self.alias_refcount[old_alias]
    780776            del self.alias_refcount[old_alias]
    781777            self.alias_map[new_alias] = tuple(alias_data)
    class Query(object):  
    923919            self.join_map[t_ident] += (alias,)
    924920        else:
    925921            self.join_map[t_ident] = (alias,)
    926         self.rev_join_map[alias] = t_ident
    927922        return alias
    928923
    929924    def setup_inherited_models(self):
Back to Top