diff options
author | Guo Xiang Tan <tgx_world@hotmail.com> | 2018-08-21 23:23:17 +0800 |
---|---|---|
committer | Guo Xiang Tan <tgx_world@hotmail.com> | 2018-09-03 13:34:24 +0800 |
commit | 90240f664c1c9e294f4230431fe2284ded19b58c (patch) | |
tree | 06c3d7f1fd368fff3255f0b5bd5bdfdf3455661d /activerecord/lib | |
parent | f3fe56c7326ed38f218c4c61e3395052e9d75d71 (diff) | |
download | rails-90240f664c1c9e294f4230431fe2284ded19b58c.tar.gz rails-90240f664c1c9e294f4230431fe2284ded19b58c.tar.bz2 rails-90240f664c1c9e294f4230431fe2284ded19b58c.zip |
Fix regression setting children record in parent before_save callback.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 10 |
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 |