From c41247a3d273f415cf2c7aae7aff490234815ad9 Mon Sep 17 00:00:00 2001 From: Tobias Kraze Date: Tue, 27 Jun 2017 17:41:39 +0200 Subject: 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. --- .../lib/active_record/associations/has_many_through_association.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/lib') 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 -- cgit v1.2.3