lib/torque/postgresql/auxiliary_statement.rb in torque-postgresql-1.1.2 vs lib/torque/postgresql/auxiliary_statement.rb in torque-postgresql-1.1.3
- old
+ new
@@ -29,15 +29,16 @@
There's no '#{statement}' auxiliary statement defined for #{base.class.name}.
MSG
end
# Fast access to statement build
- def build(statement, base, options = nil, bound_attributes = [])
+ def build(statement, base, options = nil, bound_attributes = [], join_sources = [])
klass = instantiate(statement, base, options)
result = klass.build(base)
bound_attributes.concat(klass.bound_attributes)
+ join_sources.concat(klass.join_sources)
result
end
# Identify if the query set may be used as a relation
def relation_query?(obj)
@@ -103,11 +104,11 @@
end
delegate :config, :table, :table_name, :relation, :configure, :relation_query?,
to: :class
- attr_reader :bound_attributes
+ attr_reader :bound_attributes, :join_sources
# Start a new auxiliary statement giving extra options
def initialize(*args)
options = args.extract_options!
args_key = Torque::PostgreSQL.config.auxiliary_statement.send_arguments_key
@@ -115,19 +116,21 @@
@join = options.fetch(:join, {})
@args = options.fetch(args_key, {})
@where = options.fetch(:where, {})
@select = options.fetch(:select, {})
@join_type = options.fetch(:join_type, nil)
+
@bound_attributes = []
+ @join_sources = []
end
# Build the statement on the given arel and return the WITH statement
def build(base)
prepare(base)
# Add the join condition to the list
- base.joins_values += [build_join(base)]
+ @join_sources << build_join(base)
# Return the statement with its dependencies
[@dependencies, ::Arel::Nodes::As.new(table, build_query(base))]
end
@@ -286,10 +289,10 @@
next if base.auxiliary_statements_values.any? do |cte|
cte.is_a?(dependent_klass)
end
- AuxiliaryStatement.build(dependent, base, options, bound_attributes)
+ AuxiliaryStatement.build(dependent, base, options, bound_attributes, join_sources)
end
end
# Project a column on a given table, or use the column table
def project(column, arel_table = nil)