From 41d34ae68fc09474d88ed286890f4e73e815fb66 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 29 Jan 2018 06:45:10 +0900 Subject: Allow expanding an array of `composed_of` objects --- activerecord/lib/active_record/sanitization.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb index 4acc491104..173794b8f4 100644 --- a/activerecord/lib/active_record/sanitization.rb +++ b/activerecord/lib/active_record/sanitization.rb @@ -155,12 +155,10 @@ module ActiveRecord if aggregation = reflect_on_aggregation(attr.to_sym) mapping = aggregation.mapping mapping.each do |field_attr, aggregate_attr| - expanded_attrs[field_attr] = if mapping.size == 1 && !value.respond_to?(aggregate_attr) - if value.is_a?(Array) - value.map { |it| it.respond_to?(aggregate_attr) ? it.send(aggregate_attr) : it } - else - value - end + 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 value.send(aggregate_attr) end -- cgit v1.2.3