From 24c4195bab27ed9d76d0e126044e7f932de9e30e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 8 Jul 2013 14:31:10 -0700 Subject: refactor to_sql so it does not depend on the to_sql implementation of the connection --- activerecord/lib/active_record/relation.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 612f376c55..4e86e905ed 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -502,12 +502,19 @@ module ActiveRecord # # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar' def to_sql @to_sql ||= begin + relation = self + connection = klass.connection + visitor = connection.visitor + if eager_loading? join_dependency = construct_join_dependency - relation = construct_relation_for_association_find(join_dependency) - klass.connection.to_sql(relation.arel, relation.bind_values) - else - klass.connection.to_sql(arel, bind_values.dup) + relation = construct_relation_for_association_find(join_dependency) + end + + ast = relation.arel.ast + binds = relation.bind_values.dup + visitor.accept(ast) do + connection.quote(*binds.shift.reverse) end end end -- cgit v1.2.3