diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2017-01-03 16:18:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-03 16:18:45 -0500 |
commit | f8e040957be9a3835782313c57d25d1e2d86e8dc (patch) | |
tree | 62cd3bf716af3400c441e2e5077bafdd31a6bbf7 /activerecord | |
parent | 1511f0e738f8e5ab303fc8394b63eebd81090b63 (diff) | |
parent | d4a62096ec5ec53a542f25c17a2d125f93ab21a5 (diff) | |
download | rails-f8e040957be9a3835782313c57d25d1e2d86e8dc.tar.gz rails-f8e040957be9a3835782313c57d25d1e2d86e8dc.tar.bz2 rails-f8e040957be9a3835782313c57d25d1e2d86e8dc.zip |
Merge pull request #26352 from kamipo/avoid_to_call_set_inverse_instance_twice
Avoid to call `set_inverse_instance` twice for `has_many` association
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 1 |
2 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 9fa8b5d469..0437a79b84 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -297,6 +297,8 @@ module ActiveRecord target << record end + set_inverse_instance(record) + yield(record) if block_given? rescue if index @@ -309,7 +311,6 @@ module ActiveRecord end callback(:after_add, record) unless skip_callbacks - set_inverse_instance(record) record end diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index c5a7d92a2b..25613d2fa7 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -31,7 +31,6 @@ module ActiveRecord def insert_record(record, validate = true, raise = false) set_owner_attributes(record) - set_inverse_instance(record) if raise record.save!(validate: validate) |