aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorEileen M. Uchitelle <eileencodes@users.noreply.github.com>2017-06-28 08:20:57 -0400
committerGitHub <noreply@github.com>2017-06-28 08:20:57 -0400
commitf138ffab130488348cc41cba1bceba9535141373 (patch)
treebf88043478b22f0ec8f1fab61e459b8a0ab3737b /activerecord/lib
parentd766b64b7e137955b7c7dbab51d2b6e525de47c1 (diff)
parentc41247a3d273f415cf2c7aae7aff490234815ad9 (diff)
downloadrails-f138ffab130488348cc41cba1bceba9535141373.tar.gz
rails-f138ffab130488348cc41cba1bceba9535141373.tar.bz2
rails-f138ffab130488348cc41cba1bceba9535141373.zip
Merge pull request #29593 from kratob/master
ActiveRecord: do not create "has many through" records that have been removed
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb5
1 files changed, 5 insertions, 0 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 53ffb3b68d..2fd20b4368 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -109,6 +109,11 @@ module ActiveRecord
record
end
+ def remove_records(existing_records, records, method)
+ super
+ delete_through_records(records)
+ end
+
def target_reflection_has_associated_record?
!(through_reflection.belongs_to? && owner[through_reflection.foreign_key].blank?)
end