diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 12:02:43 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 12:02:43 -0700 |
commit | 1794ac0197501c8d416c37769f2b5683d297ce6f (patch) | |
tree | 341f2654c656583652ad2ae400e17a4ee6e62fe9 | |
parent | a14f746bf0aac3f5e21b8d5b5d9672ba0d1dd979 (diff) | |
download | rails-1794ac0197501c8d416c37769f2b5683d297ce6f.tar.gz rails-1794ac0197501c8d416c37769f2b5683d297ce6f.tar.bz2 rails-1794ac0197501c8d416c37769f2b5683d297ce6f.zip |
remove the bind substitution visitor. to_sql should never return bind values
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 11 | ||||
-rw-r--r-- | activerecord/test/cases/relation/merging_test.rb | 4 |
3 files changed, 7 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index ebf77b9bfb..605156c381 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -105,10 +105,6 @@ module ActiveRecord @prepared_statements = false end - def bind_substitution_visitor - @bind_sub_visitor ||= visitor.dup.extend(Arel::Visitors::BindVisitor) - end - def valid_type?(type) true end diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 90bf751206..a0e84201be 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +require 'arel/collectors/bind' module ActiveRecord # = Active Record Relation @@ -512,17 +513,17 @@ module ActiveRecord @to_sql ||= begin relation = self connection = klass.connection - visitor = connection.bind_substitution_visitor + visitor = connection.visitor if eager_loading? find_with_associations { |rel| relation = rel } end arel = relation.arel - binds = arel.bind_values + relation.bind_values - visitor.compile(arel.ast) do - connection.quote(*binds.shift.reverse) - end + 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 diff --git a/activerecord/test/cases/relation/merging_test.rb b/activerecord/test/cases/relation/merging_test.rb index f7cd6d75b5..ff1c2a0d82 100644 --- a/activerecord/test/cases/relation/merging_test.rb +++ b/activerecord/test/cases/relation/merging_test.rb @@ -17,9 +17,7 @@ class RelationMergingTest < ActiveRecord::TestCase end def test_relation_to_sql - sql = Post.connection.unprepared_statement do - Post.first.comments.to_sql - end + sql = Post.first.comments.to_sql assert_no_match(/\?/, sql) end |