Ticket #10790: django1.1-ticket10790.patch
File django1.1-ticket10790.patch, 5.2 KB (added by , 15 years ago) |
---|
-
django/db/models/sql/expressions.py
39 39 self.cols[node] = query.aggregate_select[node.name] 40 40 else: 41 41 try: 42 field, source, opts, join_list, last, _ = query.setup_joins(42 field, source, opts, join_list, last, _, allow_trim_join = query.setup_joins( 43 43 field_list, query.get_meta(), 44 44 query.get_initial_alias(), False) 45 45 col, _, join_list = query.trim_joins(source, join_list, last, False) -
django/db/models/sql/query.py
991 991 pieces = name.split(LOOKUP_SEP) 992 992 if not alias: 993 993 alias = self.get_initial_alias() 994 field, target, opts, joins, last, extra = self.setup_joins(pieces,994 field, target, opts, joins, last, extra, allow_trim_join = self.setup_joins(pieces, 995 995 opts, alias, False) 996 996 alias = joins[-1] 997 997 col = target.column … … 1474 1474 # - this is an annotation over a model field 1475 1475 # then we need to explore the joins that are required. 1476 1476 1477 field, source, opts, join_list, last, _ = self.setup_joins(1477 field, source, opts, join_list, last, _, allow_trim_join = self.setup_joins( 1478 1478 field_list, opts, self.get_initial_alias(), False) 1479 1479 1480 1480 # Process the join chain to see if it can be trimmed … … 1571 1571 allow_many = trim or not negate 1572 1572 1573 1573 try: 1574 field, target, opts, join_list, last, extra_filters = self.setup_joins(1574 field, target, opts, join_list, last, extra_filters, allow_trim_join = self.setup_joins( 1575 1575 parts, opts, alias, True, allow_many, can_reuse=can_reuse, 1576 1576 negate=negate, process_extras=process_extras) 1577 1577 except MultiJoin, e: … … 1584 1584 # If the comparison is against NULL, we may need to use some left 1585 1585 # outer joins when creating the join chain. This is only done when 1586 1586 # needed, as it's less efficient at the database level. 1587 self.promote_alias_chain(join_list)1588 1587 1588 # If we have a one2one or many2one field, we can trim the left outer 1589 # join from the end of a list of joins. 1590 # We do not promote left outer join in this case so that trim_joins can 1591 # do it for us. 1592 if not (allow_trim_join and field.rel): 1593 self.promote_alias_chain(join_list) 1594 1589 1595 # Process the join list to see if we can remove any inner joins from 1590 1596 # the far end (fewer tables in a query is better). 1591 1597 col, alias, join_list = self.trim_joins(target, join_list, last, trim) … … 1719 1725 dupe_set = set() 1720 1726 exclusions = set() 1721 1727 extra_filters = [] 1728 allow_trim_join = True 1722 1729 for pos, name in enumerate(names): 1723 1730 try: 1724 1731 exclusions.add(int_alias) … … 1743 1750 raise FieldError("Cannot resolve keyword %r into field. " 1744 1751 "Choices are: %s" % (name, ", ".join(names))) 1745 1752 1753 # presence of indirect field in the filter requires 1754 # left outer join for isnull 1755 if not direct and allow_trim_join: 1756 allow_trim_join = False 1757 1746 1758 if not allow_many and (m2m or not direct): 1747 1759 for alias in joins: 1748 1760 self.unref_alias(alias) … … 1784 1796 extra_filters.extend(field.extra_filters(names, pos, negate)) 1785 1797 if direct: 1786 1798 if m2m: 1799 # null query on m2mfield requires outer join 1800 allow_trim_join = False 1787 1801 # Many-to-many field defined on the current model. 1788 1802 if cached_data: 1789 1803 (table1, from_col1, to_col1, table2, from_col2, … … 1893 1907 else: 1894 1908 raise FieldError("Join on field %r not permitted." % name) 1895 1909 1896 return field, target, opts, joins, last, extra_filters 1910 return field, target, opts, joins, last, extra_filters, allow_trim_join 1897 1911 1898 1912 def trim_joins(self, target, join_list, last, trim): 1899 1913 """ … … 2042 2056 2043 2057 try: 2044 2058 for name in field_names: 2045 field, target, u2, joins, u3, u4 = self.setup_joins(2059 field, target, u2, joins, u3, u4, allow_trim_join = self.setup_joins( 2046 2060 name.split(LOOKUP_SEP), opts, alias, False, allow_m2m, 2047 2061 True) 2048 2062 final_alias = joins[-1] … … 2326 2340 """ 2327 2341 opts = self.model._meta 2328 2342 alias = self.get_initial_alias() 2329 field, col, opts, joins, last, extra = self.setup_joins(2343 field, col, opts, joins, last, extra, allow_trim_join = self.setup_joins( 2330 2344 start.split(LOOKUP_SEP), opts, alias, False) 2331 2345 select_col = self.alias_map[joins[1]][LHS_JOIN_COL] 2332 2346 select_alias = alias