Skip to content

Commit 3835970

Browse files
author
Carlos Silva
committed
Fix problem with newly versions of active record
1 parent 9ac0c3d commit 3835970

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

lib/torque/postgresql/auxiliary_statement.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ def instantiate(statement, base, options = nil)
3131
end
3232

3333
# 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 = [])
3535
klass = instantiate(statement, base, options)
3636
result = klass.build(base)
3737

3838
bound_attributes.concat(klass.bound_attributes)
39+
join_sources.concat(klass.join_sources)
3940
result
4041
end
4142

@@ -105,7 +106,7 @@ def table_name
105106
delegate :config, :table, :table_name, :relation, :configure, :relation_query?,
106107
to: :class
107108

108-
attr_reader :bound_attributes
109+
attr_reader :bound_attributes, :join_sources
109110

110111
# Start a new auxiliary statement giving extra options
111112
def initialize(*args)
@@ -117,15 +118,17 @@ def initialize(*args)
117118
@where = options.fetch(:where, {})
118119
@select = options.fetch(:select, {})
119120
@join_type = options.fetch(:join_type, nil)
121+
120122
@bound_attributes = []
123+
@join_sources = []
121124
end
122125

123126
# Build the statement on the given arel and return the WITH statement
124127
def build(base)
125128
prepare(base)
126129

127130
# Add the join condition to the list
128-
base.joins_values += [build_join(base)]
131+
@join_sources << build_join(base)
129132

130133
# Return the statement with its dependencies
131134
[@dependencies, ::Arel::Nodes::As.new(table, build_query(base))]
@@ -288,7 +291,7 @@ def ensure_dependencies(list, base)
288291
cte.is_a?(dependent_klass)
289292
end
290293

291-
AuxiliaryStatement.build(dependent, base, options, bound_attributes)
294+
AuxiliaryStatement.build(dependent, base, options, bound_attributes, join_sources)
292295
end
293296
end
294297

lib/torque/postgresql/relation/auxiliary_statement.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ def bound_attributes
4747

4848
# Hook arel build to add the distinct on clause
4949
def build_arel(*)
50-
subqueries = build_auxiliary_statements
51-
return super if subqueries.nil?
52-
super.with(subqueries)
50+
arel = super
51+
subqueries = build_auxiliary_statements(arel)
52+
subqueries.nil? ? arel : arel.with(subqueries)
5353
end
5454

5555
# Build all necessary data for auxiliary statements
56-
def build_auxiliary_statements
57-
return unless self.auxiliary_statements_values.present?
58-
self.auxiliary_statements_values.map do |klass|
59-
klass.build(self)
56+
def build_auxiliary_statements(arel)
57+
return unless auxiliary_statements_values.present?
58+
auxiliary_statements_values.map do |klass|
59+
klass.build(self).tap { arel.join_sources.concat(klass.join_sources) }
6060
end
6161
end
6262

lib/torque/postgresql/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Torque
22
module PostgreSQL
3-
VERSION = '1.1.2'
3+
VERSION = '1.1.3'
44
end
55
end

0 commit comments

Comments
 (0)