Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18014 -- Removed rev_join_map from sql/query.py.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17878 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4f623524125ce059951ab879d34b50f6024225f4 1 parent 393aeb7
Anssi Kääriäinen authored April 08, 2012

Showing 1 changed file with 7 additions and 13 deletions. Show diff stats Hide diff stats

  1. 20  django/db/models/sql/query.py
20  django/db/models/sql/query.py
@@ -104,7 +104,6 @@ def __init__(self, model, where=WhereNode):
104 104
         self.alias_map = {}     # Maps alias to join information
105 105
         self.table_map = {}     # Maps table names to list of aliases.
106 106
         self.join_map = {}
107  
-        self.rev_join_map = {}  # Reverse of join_map.
108 107
         self.quote_cache = {}
109 108
         self.default_cols = True
110 109
         self.default_ordering = True
@@ -244,7 +243,6 @@ def clone(self, klass=None, memo=None, **kwargs):
244 243
         obj.alias_map = self.alias_map.copy()
245 244
         obj.table_map = self.table_map.copy()
246 245
         obj.join_map = self.join_map.copy()
247  
-        obj.rev_join_map = self.rev_join_map.copy()
248 246
         obj.quote_cache = {}
249 247
         obj.default_cols = self.default_cols
250 248
         obj.default_ordering = self.default_ordering
@@ -463,18 +461,19 @@ def combine(self, rhs, connector):
463 461
         change_map = {}
464 462
         used = set()
465 463
         conjunction = (connector == AND)
  464
+        # Add the joins in the rhs query into the new query.
466 465
         first = True
467 466
         for alias in rhs.tables:
468 467
             if not rhs.alias_refcount[alias]:
469 468
                 # An unused alias.
470 469
                 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
473 472
             # If the left side of the join was already relabeled, use the
474 473
             # updated alias.
475 474
             lhs = change_map.get(lhs, lhs)
476 475
             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)
478 477
             used.add(new_alias)
479 478
             change_map[alias] = new_alias
480 479
             first = False
@@ -766,16 +765,12 @@ def change_aliases(self, change_map):
766 765
                     col.relabel_aliases(change_map)
767 766
 
768 767
         # 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
769 771
         for old_alias, new_alias in change_map.iteritems():
770 772
             alias_data = list(self.alias_map[old_alias])
771 773
             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]
779 774
             self.alias_refcount[new_alias] = self.alias_refcount[old_alias]
780 775
             del self.alias_refcount[old_alias]
781 776
             self.alias_map[new_alias] = tuple(alias_data)
@@ -923,7 +918,6 @@ def join(self, connection, always_create=False, exclusions=(),
923 918
             self.join_map[t_ident] += (alias,)
924 919
         else:
925 920
             self.join_map[t_ident] = (alias,)
926  
-        self.rev_join_map[alias] = t_ident
927 921
         return alias
928 922
 
929 923
     def setup_inherited_models(self):

0 notes on commit 4f62352

Please sign in to comment.
Something went wrong with that request. Please try again.