aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/sanitization.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-29 07:15:55 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-01-29 07:16:28 +0900
commit1c239df3deb349650be9b305b2c8980d6659ab3e (patch)
tree6da86dcf44b0fceb8697294639e7faa982e4e6a3 /activerecord/lib/active_record/sanitization.rb
parent970b5e150c5beb523a475cdc2b3cb218edfc771d (diff)
parent41d34ae68fc09474d88ed286890f4e73e815fb66 (diff)
downloadrails-1c239df3deb349650be9b305b2c8980d6659ab3e.tar.gz
rails-1c239df3deb349650be9b305b2c8980d6659ab3e.tar.bz2
rails-1c239df3deb349650be9b305b2c8980d6659ab3e.zip
Merge pull request #31724 from orekyuu/fix-expand-composed-object-array
Fix not expanded problem when passing an Array object as argument to the where method using composed_of column.
Diffstat (limited to 'activerecord/lib/active_record/sanitization.rb')
-rw-r--r--activerecord/lib/active_record/sanitization.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb
index 58da106092..173794b8f4 100644
--- a/activerecord/lib/active_record/sanitization.rb
+++ b/activerecord/lib/active_record/sanitization.rb
@@ -155,10 +155,12 @@ module ActiveRecord
if aggregation = reflect_on_aggregation(attr.to_sym)
mapping = aggregation.mapping
mapping.each do |field_attr, aggregate_attr|
- if mapping.size == 1 && !value.respond_to?(aggregate_attr)
- expanded_attrs[field_attr] = value
+ expanded_attrs[field_attr] = if value.is_a?(Array)
+ value.map { |it| it.send(aggregate_attr) }
+ elsif mapping.size == 1 && !value.respond_to?(aggregate_attr)
+ value
else
- expanded_attrs[field_attr] = value.send(aggregate_attr)
+ value.send(aggregate_attr)
end
end
else