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