diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2015-12-31 04:18:16 -0200 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2015-12-31 04:18:16 -0200 |
commit | f2cd0eaa94dda67d24ed43e68c2094396816e7f8 (patch) | |
tree | ef3389855af70a2a1387691e85fd3bfab6a7ef89 /activerecord/lib/active_record | |
parent | 1f85e1c9f34c7b0bdc1bddad5f914d61cb2a5435 (diff) | |
parent | e110094a80c54329dde8f77cb36c62b71921ce44 (diff) | |
download | rails-f2cd0eaa94dda67d24ed43e68c2094396816e7f8.tar.gz rails-f2cd0eaa94dda67d24ed43e68c2094396816e7f8.tar.bz2 rails-f2cd0eaa94dda67d24ed43e68c2094396816e7f8.zip |
Merge pull request #22105 from morgoth/fix-errors-details-on-autosave-associations
Fixed setting errors details on autosaved associations
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index fc12c3f45a..bac5a38a5d 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -331,15 +331,30 @@ module ActiveRecord validation_context = self.validation_context unless [:create, :update].include?(self.validation_context) unless valid = record.valid?(validation_context) if reflection.options[:autosave] + indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord::Base.index_nested_attribute_errors) + record.errors.each do |attribute, message| - if index.nil? || (!reflection.options[:index_errors] && !ActiveRecord::Base.index_nested_attribute_errors) - attribute = "#{reflection.name}.#{attribute}" - else + if indexed_attribute attribute = "#{reflection.name}[#{index}].#{attribute}" + else + attribute = "#{reflection.name}.#{attribute}" end errors[attribute] << message errors[attribute].uniq! end + + record.errors.details.each_key do |attribute| + if indexed_attribute + reflection_attribute = "#{reflection.name}[#{index}].#{attribute}" + else + reflection_attribute = "#{reflection.name}.#{attribute}" + end + + record.errors.details[attribute].each do |error| + errors.details[reflection_attribute] << error + errors.details[reflection_attribute].uniq! + end + end else errors.add(reflection.name) end |