to_sql()
public
Returns sql statement for the relation.
User.where(name: 'Oscar').to_sql
# File activerecord/lib/active_record/relation.rb, line 569
def to_sql
@to_sql ||= begin
relation = self
if eager_loading?
find_with_associations { |rel, _| relation = rel }
end
conn = klass.connection
conn.unprepared_statement {
conn.to_sql(relation.arel, relation.bound_attributes)
}
end
end