diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-12-29 16:17:01 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-12-29 16:24:57 +0900 |
commit | 9abf606a79729833fd90f624ed580ad85f3ebadc (patch) | |
tree | 2ae13816024dd83168aadee998ace0505734dc65 /activerecord/lib/active_record | |
parent | 366f094598305074c4430fab581ddfd599c1cf96 (diff) | |
download | rails-9abf606a79729833fd90f624ed580ad85f3ebadc.tar.gz rails-9abf606a79729833fd90f624ed580ad85f3ebadc.tar.bz2 rails-9abf606a79729833fd90f624ed580ad85f3ebadc.zip |
Should not update children when the parent creation with no reason
This issue was introduced with d849f42 to solve #19782. However, we can
solve #19782 without causing the issue. It is enough to save only when
necessary.
Fixes #27338.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 0c0aefe3b9..c4a7fe4432 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -38,10 +38,12 @@ module ActiveRecord def insert_record(record, validate = true, raise = false) ensure_not_nested - if raise - record.save!(validate: validate) - else - return unless record.save(validate: validate) + if record.new_record? || record.has_changes_to_save? + if raise + record.save!(validate: validate) + else + return unless record.save(validate: validate) + end end save_through_record(record) |