aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorlulalala <mark@goodlife.tw>2018-03-26 13:36:56 +0800
committerlulalala <mark@goodlife.tw>2019-03-31 22:59:12 +0800
commit8c8b0b670c680bc89e80e9dff9eb144c4a07e28a (patch)
tree3397237431766e256332452f1a61baa37b4bc5e1 /activerecord/lib/active_record
parentea77205a9ff71ebd0dc7cf29e598ef126c9807f5 (diff)
downloadrails-8c8b0b670c680bc89e80e9dff9eb144c4a07e28a.tar.gz
rails-8c8b0b670c680bc89e80e9dff9eb144c4a07e28a.tar.bz2
rails-8c8b0b670c680bc89e80e9dff9eb144c4a07e28a.zip
Use errors#import instead of manipulating errors/details hash
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb21
1 files changed, 8 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index fe94662543..453c6e4c8c 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -330,21 +330,16 @@ module ActiveRecord
if reflection.options[:autosave]
indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord::Base.index_nested_attribute_errors)
- record.errors.each do |attribute, message|
+ record.errors.group_by_attribute.each { |attribute, errors|
attribute = normalize_reflection_attribute(indexed_attribute, reflection, index, attribute)
- errors[attribute] << message
- errors[attribute].uniq!
- end
-
- record.errors.details.each_key do |attribute|
- reflection_attribute =
- normalize_reflection_attribute(indexed_attribute, reflection, index, attribute).to_sym
- record.errors.details[attribute].each do |error|
- errors.details[reflection_attribute] << error
- errors.details[reflection_attribute].uniq!
- end
- end
+ errors.each { |error|
+ self.errors.import(
+ error,
+ attribute: attribute
+ )
+ }
+ }
else
errors.add(reflection.name)
end