aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-12-17 12:54:27 -0700
committerSean Griffin <sean@seantheprogrammer.com>2015-12-17 12:54:46 -0700
commitcd395b9419ac3a860ee78cf9706af1bf7d86fe92 (patch)
tree55e2b126325cbfea1348bcd856610ce8d9f8bcc0
parentf726dbe0802395aabf9cc99fe34bc69b375bf344 (diff)
downloadrails-cd395b9419ac3a860ee78cf9706af1bf7d86fe92.tar.gz
rails-cd395b9419ac3a860ee78cf9706af1bf7d86fe92.tar.bz2
rails-cd395b9419ac3a860ee78cf9706af1bf7d86fe92.zip
Inject the visitor rather than relying on other objects internals
This is ultimately messy no matter what, and increases the coupling to the database backend, but we can at least contain it somewhat into an object that's already coupled.
-rw-r--r--lib/arel/select_manager.rb2
-rw-r--r--lib/arel/visitors/where_sql.rb7
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index f7dec87ca3..eae3bc8cbc 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -179,7 +179,7 @@ module Arel
def where_sql engine = Table.engine
return if @ctx.wheres.empty?
- viz = Visitors::WhereSql.new engine.connection
+ viz = Visitors::WhereSql.new(engine.connection.visitor, engine.connection)
Nodes::SqlLiteral.new viz.accept(@ctx, Collectors::SQLString.new).value
end
diff --git a/lib/arel/visitors/where_sql.rb b/lib/arel/visitors/where_sql.rb
index 80797205c9..41972d5836 100644
--- a/lib/arel/visitors/where_sql.rb
+++ b/lib/arel/visitors/where_sql.rb
@@ -1,12 +1,17 @@
module Arel
module Visitors
class WhereSql < Arel::Visitors::ToSql
+ def initialize(inner_visitor, *args, &block)
+ @inner_visitor = inner_visitor
+ super(*args, &block)
+ end
+
private
def visit_Arel_Nodes_SelectCore o, collector
collector << "WHERE "
wheres = o.wheres.map do |where|
- Nodes::SqlLiteral.new(@connection.visitor.accept(where, collector.class.new).value)
+ Nodes::SqlLiteral.new(@inner_visitor.accept(where, collector.class.new).value)
end
inject_join wheres, collector, ' AND '