diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index ed2bc06..dbac57b 100644
a
|
b
|
from django.core.exceptions import FieldError
|
27 | 27 | |
28 | 28 | __all__ = ['Query', 'RawQuery'] |
29 | 29 | |
| 30 | try: |
| 31 | from collections import namedtuple |
| 32 | except ImportError: |
| 33 | # Python < 2.6 |
| 34 | JoinExpr = tuple |
| 35 | else: |
| 36 | _JoinExpr = namedtuple("_JoinExpr", |
| 37 | # This basicaly describes the following SQL expression: |
| 38 | # |
| 39 | # {join_type} JOIN {table_name} [AS {rhs_alias}] |
| 40 | # ON ({lhs_alias}.{lhs_join_col} = {rhs_alias}.{rhs_join_col}) |
| 41 | # |
| 42 | "table_name," # Original table_name as in Query.tables |
| 43 | "rhs_alias," |
| 44 | "join_type," # INNER, OUTER or None (= base table, not really being joined) |
| 45 | "lhs_alias," |
| 46 | "lhs_join_col," |
| 47 | "rhs_join_col," |
| 48 | # Can the right hand values be NULL ? This is used in promote_alias() |
| 49 | # to check if INNER JOIN should be promoted to OUTER JOIN |
| 50 | "nullable," |
| 51 | ) |
| 52 | JoinExpr = _JoinExpr._make |
| 53 | |
| 54 | |
30 | 55 | class RawQuery(object): |
31 | 56 | """ |
32 | 57 | A single raw SQL query |
… |
… |
class Query(object):
|
696 | 721 | self.alias_map[alias][JOIN_TYPE] != self.LOUTER): |
697 | 722 | data = list(self.alias_map[alias]) |
698 | 723 | data[JOIN_TYPE] = self.LOUTER |
699 | | self.alias_map[alias] = tuple(data) |
| 724 | self.alias_map[alias] = JoinExpr(data) |
700 | 725 | return True |
701 | 726 | return False |
702 | 727 | |
… |
… |
class Query(object):
|
781 | 806 | del self.rev_join_map[old_alias] |
782 | 807 | self.alias_refcount[new_alias] = self.alias_refcount[old_alias] |
783 | 808 | del self.alias_refcount[old_alias] |
784 | | self.alias_map[new_alias] = tuple(alias_data) |
| 809 | self.alias_map[new_alias] = JoinExpr(alias_data) |
785 | 810 | del self.alias_map[old_alias] |
786 | 811 | |
787 | 812 | table_aliases = self.table_map[alias_data[TABLE_NAME]] |
… |
… |
class Query(object):
|
803 | 828 | if lhs in change_map: |
804 | 829 | data = list(data) |
805 | 830 | data[LHS_ALIAS] = change_map[lhs] |
806 | | self.alias_map[alias] = tuple(data) |
| 831 | self.alias_map[alias] = JoinExpr(data) |
807 | 832 | |
808 | 833 | def bump_prefix(self, exceptions=()): |
809 | 834 | """ |
… |
… |
class Query(object):
|
920 | 945 | join_type = self.LOUTER |
921 | 946 | else: |
922 | 947 | join_type = self.INNER |
923 | | join = (table, alias, join_type, lhs, lhs_col, col, nullable) |
| 948 | join = JoinExpr((table, alias, join_type, lhs, lhs_col, col, nullable)) |
924 | 949 | self.alias_map[alias] = join |
925 | 950 | if t_ident in self.join_map: |
926 | 951 | self.join_map[t_ident] += (alias,) |