diff options
author | Paul Nikitochkin <paul.nikitochkin@gmail.com> | 2013-10-18 23:26:39 +0300 |
---|---|---|
committer | Paul Nikitochkin <paul.nikitochkin@gmail.com> | 2013-10-20 21:07:07 +0300 |
commit | a2ed5d2381079716cf6224bc7b0538d318b264a2 (patch) | |
tree | 782bc3765e915d91651402d3f079825ba7f048dc /activerecord/lib/active_record | |
parent | db82e1d0bb21c2a13354b97733c09737719e946b (diff) | |
download | rails-a2ed5d2381079716cf6224bc7b0538d318b264a2.tar.gz rails-a2ed5d2381079716cf6224bc7b0538d318b264a2.tar.bz2 rails-a2ed5d2381079716cf6224bc7b0538d318b264a2.zip |
Process sub-query relation's binding values
Generated sub-query for Relation as array condition for `where` method
did not take in account its bind values, in result generates invalid SQL query.
Fixed by adding sub-query relation's binding values to base relation
Closes: #12586
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 9c9690215a..f680d94215 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -894,6 +894,13 @@ module ActiveRecord def build_where(opts, other = []) case opts when String, Array + #TODO: Remove duplication with: /activerecord/lib/active_record/sanitization.rb:113 + values = Hash === other.first ? other.first.values : other + + values.grep(ActiveRecord::Relation) do |rel| + self.bind_values += rel.bind_values + end + [@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))] when Hash opts = PredicateBuilder.resolve_column_aliases(klass, opts) |