Ticket #2922: extra_joins.diff
File extra_joins.diff, 2.5 KB (added by , 18 years ago) |
---|
-
django/db/models/query.py
a b class QuerySet(object): 85 85 self._where = [] # List of extra WHERE clauses to use. 86 86 self._params = [] # List of params to use for extra WHERE clauses. 87 87 self._tables = [] # List of extra tables to use. 88 self._joins = [] # List of extra joins to use. 88 89 self._offset = None # OFFSET clause. 89 90 self._limit = None # LIMIT clause. 90 91 self._result_cache = None … … class QuerySet(object): 379 380 "Returns a new QuerySet instance with '_distinct' modified." 380 381 return self._clone(_distinct=true_or_false) 381 382 382 def extra(self, select=None, where=None, params=None, tables=None ):383 def extra(self, select=None, where=None, params=None, tables=None, joins=None): 383 384 assert self._limit is None and self._offset is None, \ 384 385 "Cannot change a query once a slice has been taken" 385 386 clone = self._clone() … … class QuerySet(object): 387 388 if where: clone._where.extend(where) 388 389 if params: clone._params.extend(params) 389 390 if tables: clone._tables.extend(tables) 391 if joins: clone._joins.extend(joins) 390 392 return clone 391 393 392 394 ######################## … … class QuerySet(object): 429 431 c._where = self._where[:] 430 432 c._params = self._params[:] 431 433 c._tables = self._tables[:] 434 c._joins = self._joins[:] 432 435 c._offset = self._offset 433 436 c._limit = self._limit 434 437 c.__dict__.update(kwargs) … … class QuerySet(object): 448 451 if self._where: combined._where.extend(self._where) 449 452 if self._params: combined._params.extend(self._params) 450 453 if self._tables: combined._tables.extend(self._tables) 454 if self._joins: combined._joins.extend(self._joins) 451 455 # If 'self' is ordered and 'other' isn't, propagate 'self's ordering 452 456 if (self._order_by is not None and len(self._order_by) > 0) and \ 453 457 (combined._order_by is None or len(combined._order_by) == 0): … … class QuerySet(object): 490 494 if joins: 491 495 sql.append(" ".join(["%s %s AS %s ON %s" % (join_type, table, alias, condition) 492 496 for (alias, (table, join_type, condition)) in joins.items()])) 497 if self._joins: 498 sql.append(" ".join(self._joins)) 493 499 494 500 # Compose the tables clause into SQL. 495 501 if tables: