@@ -31,11 +31,12 @@ def instantiate(statement, base, options = nil)
31
31
end
32
32
33
33
# Fast access to statement build
34
- def build ( statement , base , options = nil , bound_attributes = [ ] )
34
+ def build ( statement , base , options = nil , bound_attributes = [ ] , join_sources = [ ] )
35
35
klass = instantiate ( statement , base , options )
36
36
result = klass . build ( base )
37
37
38
38
bound_attributes . concat ( klass . bound_attributes )
39
+ join_sources . concat ( klass . join_sources )
39
40
result
40
41
end
41
42
@@ -105,7 +106,7 @@ def table_name
105
106
delegate :config , :table , :table_name , :relation , :configure , :relation_query? ,
106
107
to : :class
107
108
108
- attr_reader :bound_attributes
109
+ attr_reader :bound_attributes , :join_sources
109
110
110
111
# Start a new auxiliary statement giving extra options
111
112
def initialize ( *args )
@@ -117,15 +118,17 @@ def initialize(*args)
117
118
@where = options . fetch ( :where , { } )
118
119
@select = options . fetch ( :select , { } )
119
120
@join_type = options . fetch ( :join_type , nil )
121
+
120
122
@bound_attributes = [ ]
123
+ @join_sources = [ ]
121
124
end
122
125
123
126
# Build the statement on the given arel and return the WITH statement
124
127
def build ( base )
125
128
prepare ( base )
126
129
127
130
# Add the join condition to the list
128
- base . joins_values += [ build_join ( base ) ]
131
+ @join_sources << build_join ( base )
129
132
130
133
# Return the statement with its dependencies
131
134
[ @dependencies , ::Arel ::Nodes ::As . new ( table , build_query ( base ) ) ]
@@ -288,7 +291,7 @@ def ensure_dependencies(list, base)
288
291
cte . is_a? ( dependent_klass )
289
292
end
290
293
291
- AuxiliaryStatement . build ( dependent , base , options , bound_attributes )
294
+ AuxiliaryStatement . build ( dependent , base , options , bound_attributes , join_sources )
292
295
end
293
296
end
294
297
0 commit comments