aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-13 16:45:30 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-10-13 16:45:30 -0300
commit95cb54a29ee014253665abc4e9068fffc578128d (patch)
treedf17854bf076412d7be296ee677da531d92eba05 /activerecord/lib/active_record
parent0b2884a8ae6891f6507303b487dc3deff4fb0852 (diff)
parentbc293ff690e5478b99a55594f9fa8fe0e709941b (diff)
downloadrails-95cb54a29ee014253665abc4e9068fffc578128d.tar.gz
rails-95cb54a29ee014253665abc4e9068fffc578128d.tar.bz2
rails-95cb54a29ee014253665abc4e9068fffc578128d.zip
Merge pull request #12508 from jetthoughts/12415_generate_subqueries_for_relation_from_binding_params
Generate subquery for Relation passed as array condition for where Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/sanitization.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb
index 0b87ab9926..af4ea0efec 100644
--- a/activerecord/lib/active_record/sanitization.rb
+++ b/activerecord/lib/active_record/sanitization.rb
@@ -127,7 +127,17 @@ module ActiveRecord
raise_if_bind_arity_mismatch(statement, statement.count('?'), values.size)
bound = values.dup
c = connection
- statement.gsub('?') { quote_bound_value(bound.shift, c) }
+ statement.gsub('?') do
+ replace_bind_variable(bound.shift, c)
+ end
+ end
+
+ def replace_bind_variable(value, c = connection)
+ if ActiveRecord::Relation === value
+ value.to_sql
+ else
+ quote_bound_value(value, c)
+ end
end
def replace_named_bind_variables(statement, bind_vars) #:nodoc:
@@ -135,7 +145,7 @@ module ActiveRecord
if $1 == ':' # skip postgresql casts
$& # return the whole match
elsif bind_vars.include?(match = $2.to_sym)
- quote_bound_value(bind_vars[match])
+ replace_bind_variable(bind_vars[match])
else
raise PreparedStatementInvalid, "missing value for :#{match} in #{statement}"
end