aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorTobias Kraze <tobias.kraze@makandra.de>2017-06-27 17:41:39 +0200
committerTobias Kraze <tobias.kraze@makandra.de>2017-06-28 14:18:48 +0200
commitc41247a3d273f415cf2c7aae7aff490234815ad9 (patch)
tree22c10ef00798382e0ca8537c58103fbaaf684911 /activerecord/lib
parent61cc630ac7e7f8554dc049a3e5a2509c00303ef8 (diff)
downloadrails-c41247a3d273f415cf2c7aae7aff490234815ad9.tar.gz
rails-c41247a3d273f415cf2c7aae7aff490234815ad9.tar.bz2
rails-c41247a3d273f415cf2c7aae7aff490234815ad9.zip
ActiveRecord: do not create "has many through" records that have been removed
If a record was built on a HasManyThroughAssociation, then removed, and then the record was saved, the removed record would be created anyways.
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