Ticket #7231: extra-join-1.1.diff
File extra-join-1.1.diff, 2.6 KB (added by , 15 years ago) |
---|
-
django/db/models/sql/query.py
96 96 self.extra_where = () 97 97 self.extra_params = () 98 98 self.extra_order_by = () 99 self.extra_join = () 99 100 100 101 # A tuple that is a set of model field names and either True, if these 101 102 # are the fields to defer, or False if these are the only fields to … … 236 237 obj.extra_where = self.extra_where 237 238 obj.extra_params = self.extra_params 238 239 obj.extra_order_by = self.extra_order_by 240 obj.extra_join = self.extra_join 239 241 obj.deferred_loading = deepcopy(self.deferred_loading) 240 242 if self.filter_is_sticky and self.used_aliases: 241 243 obj.used_aliases = self.used_aliases.copy() … … 415 417 result.append('FROM') 416 418 result.extend(from_) 417 419 params.extend(f_params) 420 421 if self.extra_join: 422 result.append(' '.join(self.extra_join)) 418 423 419 424 if where: 420 425 result.append('WHERE %s' % where) … … 2157 2162 self.related_select_cols = [] 2158 2163 self.related_select_fields = [] 2159 2164 2160 def add_extra(self, select, select_params, where, params, tables, order_by ):2165 def add_extra(self, select, select_params, where, params, tables, order_by, join): 2161 2166 """ 2162 2167 Adds data to the various extra_* attributes for user-created additions 2163 2168 to the query. … … 2190 2195 self.extra_tables += tuple(tables) 2191 2196 if order_by: 2192 2197 self.extra_order_by = order_by 2198 if join: 2199 self.extra_join += tuple(join) 2193 2200 2194 2201 def clear_deferred_loading(self): 2195 2202 """ -
django/db/models/query.py
601 601 return obj 602 602 603 603 def extra(self, select=None, where=None, params=None, tables=None, 604 order_by=None, select_params=None ):604 order_by=None, select_params=None, join=None): 605 605 """ 606 606 Adds extra SQL fragments to the query. 607 607 """ 608 608 assert self.query.can_filter(), \ 609 609 "Cannot change a query once a slice has been taken" 610 610 clone = self._clone() 611 clone.query.add_extra(select, select_params, where, params, tables, order_by )611 clone.query.add_extra(select, select_params, where, params, tables, order_by, join) 612 612 return clone 613 613 614 614 def reverse(self):