aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-09-03 15:44:00 +0900
committerGitHub <noreply@github.com>2018-09-03 15:44:00 +0900
commitc8108465cab66ff1c60d5fc19bd329ac5c1a5109 (patch)
treeabea4909ddc95210c1c05f563b6ca5948df9f805 /activerecord/lib
parent53eea40d354dafbeda1703aa0e4b4a688bc26017 (diff)
parent90240f664c1c9e294f4230431fe2284ded19b58c (diff)
downloadrails-c8108465cab66ff1c60d5fc19bd329ac5c1a5109.tar.gz
rails-c8108465cab66ff1c60d5fc19bd329ac5c1a5109.tar.bz2
rails-c8108465cab66ff1c60d5fc19bd329ac5c1a5109.zip
Merge pull request #33673 from tgxworld/regression_setting_children_record_in_parent_before_save
Fix regression setting children record in parent before_save callback.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index a405f05e0b..783a8366ce 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -392,7 +392,7 @@ module ActiveRecord
records -= records_to_destroy
end
- records.each_with_index do |record, index|
+ records.each do |record|
next if record.destroyed?
saved = true
@@ -401,11 +401,11 @@ module ActiveRecord
if autosave
saved = association.insert_record(record, false)
elsif !reflection.nested?
+ association_saved = association.insert_record(record)
+
if reflection.validate?
- valid = association_valid?(reflection, record, index)
- saved = valid ? association.insert_record(record, false) : false
- else
- association.insert_record(record)
+ errors.add(reflection.name) unless association_saved
+ saved = association_saved
end
end
elsif autosave