Code

Ticket #7231: extra-join-1.2-beta-SVN-12755.diff

File extra-join-1.2-beta-SVN-12755.diff, 3.1 KB (added by bendavis78, 4 years ago)

Updated for django 1.2-beta

Line 
1Index: django/db/models/sql/compiler.py
2===================================================================
3--- django/db/models/sql/compiler.py    (revision 12755)
4+++ django/db/models/sql/compiler.py    (working copy)
5@@ -81,6 +81,9 @@
6         result.extend(from_)
7         params.extend(f_params)
8 
9+        if self.query.extra_join:
10+            result.append(' '.join(self.query.extra_join))
11+
12         if where:
13             result.append('WHERE %s' % where)
14             params.extend(w_params)
15Index: django/db/models/sql/query.py
16===================================================================
17--- django/db/models/sql/query.py       (revision 12755)
18+++ django/db/models/sql/query.py       (working copy)
19@@ -130,6 +130,7 @@
20 
21         self.extra_tables = ()
22         self.extra_order_by = ()
23+        self.extra_join = ()
24 
25         # A tuple that is a set of model field names and either True, if these
26         # are the fields to defer, or False if these are the only fields to
27@@ -256,6 +257,7 @@
28             obj._extra_select_cache = self._extra_select_cache.copy()
29         obj.extra_tables = self.extra_tables
30         obj.extra_order_by = self.extra_order_by
31+        obj.extra_join = self.extra_join
32         obj.deferred_loading = deepcopy(self.deferred_loading, memo=memo)
33         if self.filter_is_sticky and self.used_aliases:
34             obj.used_aliases = self.used_aliases.copy()
35@@ -376,7 +378,7 @@
36 
37     def has_results(self, using):
38         q = self.clone()
39-        q.add_extra({'a': 1}, None, None, None, None, None)
40+        q.add_extra({'a': 1}, None, None, None, None, None, None)
41         q.add_fields(())
42         q.set_extra_mask(('a',))
43         q.set_aggregate_mask(())
44@@ -1578,7 +1580,7 @@
45         self.related_select_cols = []
46         self.related_select_fields = []
47 
48-    def add_extra(self, select, select_params, where, params, tables, order_by):
49+    def add_extra(self, select, select_params, where, params, tables, order_by, join)
50         """
51         Adds data to the various extra_* attributes for user-created additions
52         to the query.
53@@ -1609,6 +1611,8 @@
54             self.extra_tables += tuple(tables)
55         if order_by:
56             self.extra_order_by = order_by
57+        if join:
58+            self.extra_join += tuple(join)
59 
60     def clear_deferred_loading(self):
61         """
62Index: django/db/models/query.py
63===================================================================
64--- django/db/models/query.py   (revision 12755)
65+++ django/db/models/query.py   (working copy)
66@@ -648,7 +648,7 @@
67         return obj
68 
69     def extra(self, select=None, where=None, params=None, tables=None,
70-              order_by=None, select_params=None):
71+              order_by=None, select_params=None, join=None):
72         """
73         Adds extra SQL fragments to the query.
74         """
75@@ -656,6 +656,7 @@
76                 "Cannot change a query once a slice has been taken"
77         clone = self._clone()
78         clone.query.add_extra(select, select_params, where, params, tables, order_by)
79+        clone.query.add_extra(select, select_params, where, params, tables, order_by, join)
80         return clone
81 
82     def reverse(self):