Permalink
Browse files

refactor to_sql so it does not depend on the to_sql implementation of

the connection
  • Loading branch information...
1 parent b025fca commit 24c4195bab27ed9d76d0e126044e7f932de9e30e @tenderlove tenderlove committed Jul 8, 2013
Showing with 11 additions and 4 deletions.
  1. +11 −4 activerecord/lib/active_record/relation.rb
@@ -502,12 +502,19 @@ def reset
# # => 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

3 comments on commit 24c4195

@rafaelfranca
Member

@tenderlove there is a reason for this?

@rafaelfranca
Member

I asked because the implementation seem the same now arthurnn@28cca4f

@rafaelfranca
Member

Forget about it. adaquaterecord branch give me adequate reason

Please sign in to comment.