to_sql()
public
Returns sql statement for the relation.
User.where(name: 'Oscar').to_sql
# File activerecord/lib/active_record/relation.rb, line 537
def to_sql
@to_sql ||= begin
relation = self
connection = klass.connection
visitor = connection.visitor
if eager_loading?
find_with_associations { |rel| relation = rel }
end
arel = relation.arel
binds = (arel.bind_values + relation.bind_values).dup
binds.map! { |bv| connection.quote(*bv.reverse) }
collect = visitor.accept(arel.ast, Arel::Collectors::Bind.new)
collect.substitute_binds(binds).join
end
end