mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
f726dbe080
commit
cd395b9419
2 changed files with 7 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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 '
|
||||
|
|
Loading…
Reference in a new issue