Code

Ticket #7231: extra-join-1.1b.2.diff

File extra-join-1.1b.2.diff, 2.6 KB (added by tomas@…, 5 years ago)

Modified extra join which will not interfere with django multilingual.

Line 
1Index: django/db/models/sql/query.py
2===================================================================
3--- django/db/models/sql/query.py       (revisione 10172)
4+++ django/db/models/sql/query.py       (copia locale)
5@@ -93,6 +93,7 @@
6         self.extra_where = ()
7         self.extra_params = ()
8         self.extra_order_by = ()
9+        self.extra_join_123 = ()
10 
11         # A tuple that is a set of model field names and either True, if these
12         # are the fields to defer, or False if these are the only fields to
13@@ -211,6 +212,7 @@
14         obj.extra_where = self.extra_where
15         obj.extra_params = self.extra_params
16         obj.extra_order_by = self.extra_order_by
17+        obj.extra_join_123 = self.extra_join_123
18         obj.deferred_loading = deepcopy(self.deferred_loading)
19         if self.filter_is_sticky and self.used_aliases:
20             obj.used_aliases = self.used_aliases.copy()
21@@ -390,6 +392,9 @@
22         result.append('FROM')
23         result.extend(from_)
24         params.extend(f_params)
25+       
26+        if self.extra_join_123:
27+            result.append(' '.join(self.extra_join_123))
28 
29         if where:
30             result.append('WHERE %s' % where)
31@@ -2095,7 +2100,7 @@
32         self.related_select_cols = []
33         self.related_select_fields = []
34 
35-    def add_extra(self, select, select_params, where, params, tables, order_by):
36+    def add_extra(self, select, select_params, where, params, tables, order_by, join=None):
37         """
38         Adds data to the various extra_* attributes for user-created additions
39         to the query.
40@@ -2128,6 +2133,8 @@
41             self.extra_tables += tuple(tables)
42         if order_by:
43             self.extra_order_by = order_by
44+        if join:
45+            self.extra_join_123 += tuple(join)
46 
47     def clear_deferred_loading(self):
48         """
49Index: django/db/models/query.py
50===================================================================
51--- django/db/models/query.py   (revisione 10172)
52+++ django/db/models/query.py   (copia locale)
53@@ -570,14 +570,14 @@
54         return obj
55 
56     def extra(self, select=None, where=None, params=None, tables=None,
57-              order_by=None, select_params=None):
58+              order_by=None, select_params=None, join=None):
59         """
60         Adds extra SQL fragments to the query.
61         """
62         assert self.query.can_filter(), \
63                 "Cannot change a query once a slice has been taken"
64         clone = self._clone()
65-        clone.query.add_extra(select, select_params, where, params, tables, order_by)
66+        clone.query.add_extra(select, select_params, where, params, tables, order_by, join)
67         return clone
68 
69     def reverse(self):