aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-07-20 02:15:03 -0300
committerGitHub <noreply@github.com>2016-07-20 02:15:03 -0300
commit0d42c906c5354950ce1b185b3ff3408908929ec1 (patch)
tree03f3cc686d1cb14469adb742e18aec07eeb880f9 /activerecord/lib
parent0e825917f1ee55379543b73bee5067e840334d6a (diff)
parent3befc7a9ef4740fc4af5cc256e4c4589e0aea562 (diff)
downloadrails-0d42c906c5354950ce1b185b3ff3408908929ec1.tar.gz
rails-0d42c906c5354950ce1b185b3ff3408908929ec1.tar.bz2
rails-0d42c906c5354950ce1b185b3ff3408908929ec1.zip
Merge pull request #25888 from kamipo/use_conn_to_sql_for_construct_sql
Use `connection#to_sql` for construct an SQL
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation.rb15
1 files changed, 5 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 93baa882ad..0792ba8f76 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -1,5 +1,3 @@
-require "arel/collectors/bind"
-
module ActiveRecord
# = Active Record \Relation
class Relation
@@ -597,19 +595,16 @@ module ActiveRecord
# # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar'
def to_sql
@to_sql ||= begin
- relation = self
- connection = klass.connection
- visitor = connection.visitor
+ relation = self
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
+ conn = klass.connection
+ conn.unprepared_statement {
+ conn.to_sql(relation.arel, relation.bound_attributes)
+ }
end
end