diff -ruw Django-1.2.1.orig/django/db/models/query.py Django-1.2.1/django/db/models/query.py
old
|
new
|
|
653 | 653 | return obj |
654 | 654 | |
655 | 655 | def extra(self, select=None, where=None, params=None, tables=None, |
656 | | order_by=None, select_params=None): |
| 656 | order_by=None, select_params=None, join=None): |
657 | 657 | """ |
658 | 658 | Adds extra SQL fragments to the query. |
659 | 659 | """ |
660 | 660 | assert self.query.can_filter(), \ |
661 | 661 | "Cannot change a query once a slice has been taken" |
662 | 662 | clone = self._clone() |
663 | | clone.query.add_extra(select, select_params, where, params, tables, order_by) |
| 663 | clone.query.add_extra(select, select_params, where, params, tables, order_by, join) |
664 | 664 | return clone |
665 | 665 | |
666 | 666 | def reverse(self): |
diff -ruw Django-1.2.1.orig/django/db/models/sql/compiler.py Django-1.2.1/django/db/models/sql/compiler.py
old
|
new
|
|
77 | 77 | result.extend(from_) |
78 | 78 | params.extend(f_params) |
79 | 79 | |
| 80 | if self.query.extra_join: |
| 81 | result.append(' '.join(self.query.extra_join)) |
| 82 | |
80 | 83 | if where: |
81 | 84 | result.append('WHERE %s' % where) |
82 | 85 | params.extend(w_params) |
diff -ruw Django-1.2.1.orig/django/db/models/sql/query.py Django-1.2.1/django/db/models/sql/query.py
old
|
new
|
|
151 | 151 | |
152 | 152 | self.extra_tables = () |
153 | 153 | self.extra_order_by = () |
| 154 | self.extra_join = () |
154 | 155 | |
155 | 156 | # A tuple that is a set of model field names and either True, if these |
156 | 157 | # are the fields to defer, or False if these are the only fields to |
… |
… |
|
284 | 285 | obj._extra_select_cache = self._extra_select_cache.copy() |
285 | 286 | obj.extra_tables = self.extra_tables |
286 | 287 | obj.extra_order_by = self.extra_order_by |
| 288 | obj.extra_join = self.extra_join |
287 | 289 | obj.deferred_loading = deepcopy(self.deferred_loading, memo=memo) |
288 | 290 | if self.filter_is_sticky and self.used_aliases: |
289 | 291 | obj.used_aliases = self.used_aliases.copy() |
… |
… |
|
404 | 406 | |
405 | 407 | def has_results(self, using): |
406 | 408 | q = self.clone() |
407 | | q.add_extra({'a': 1}, None, None, None, None, None) |
| 409 | q.add_extra({'a': 1}, None, None, None, None, None, None) |
408 | 410 | q.select = [] |
409 | 411 | q.select_fields = [] |
410 | 412 | q.default_cols = False |
… |
… |
|
1609 | 1611 | self.related_select_cols = [] |
1610 | 1612 | self.related_select_fields = [] |
1611 | 1613 | |
1612 | | def add_extra(self, select, select_params, where, params, tables, order_by): |
| 1614 | def add_extra(self, select, select_params, where, params, tables, order_by, join): |
1613 | 1615 | """ |
1614 | 1616 | Adds data to the various extra_* attributes for user-created additions |
1615 | 1617 | to the query. |
… |
… |
|
1640 | 1642 | self.extra_tables += tuple(tables) |
1641 | 1643 | if order_by: |
1642 | 1644 | self.extra_order_by = order_by |
| 1645 | if join: |
| 1646 | self.extra_join += tuple(join) |
1643 | 1647 | |
1644 | 1648 | def clear_deferred_loading(self): |
1645 | 1649 | """ |