aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2014-08-14 11:08:25 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2014-08-14 11:08:25 -0300
commit71e8f199d75fcad804c6a36e089b6b8fb4071192 (patch)
tree53815e3078eb1c2278b9f6cb095daa8e5b015e3c /activerecord/lib
parentdfc3f8831189ca762b942571182228bd2d37ac53 (diff)
parentfe67dfbbeea092f0f42e81e4901fe9a949cf9484 (diff)
downloadrails-71e8f199d75fcad804c6a36e089b6b8fb4071192.tar.gz
rails-71e8f199d75fcad804c6a36e089b6b8fb4071192.tar.bz2
rails-71e8f199d75fcad804c6a36e089b6b8fb4071192.zip
Merge pull request #16502 from bogdan/where-hash-nested-relation
[Regression 4.0 -> 4.1] Fixed AR::Relation#where edge case with Hash and other Relation
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 1262b2c291..c8f382ad78 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -952,9 +952,7 @@ WARNING
self.bind_values += bind_values
attributes = @klass.send(:expand_hash_conditions_for_aggregates, tmp_opts)
- attributes.values.grep(ActiveRecord::Relation) do |rel|
- self.bind_values += rel.bind_values
- end
+ add_relations_to_bind_values(attributes)
PredicateBuilder.build_from_hash(klass, attributes, table)
else
@@ -1137,5 +1135,19 @@ WARNING
raise ArgumentError, "The method .#{method_name}() must contain arguments."
end
end
+
+ # This function is recursive just for better readablity.
+ # #where argument doesn't support more than one level nested hash in real world.
+ def add_relations_to_bind_values(attributes)
+ if attributes.is_a?(Hash)
+ attributes.each_value do |value|
+ if value.is_a?(ActiveRecord::Relation)
+ self.bind_values += value.bind_values
+ else
+ add_relations_to_bind_values(value)
+ end
+ end
+ end
+ end
end
end