aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_many_through_association.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb17
1 files changed, 8 insertions, 9 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 3174ea6373..c98ac79dc0 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -43,19 +43,18 @@ module ActiveRecord
end
end
- # TODO - add dependent option support
- def delete_records(records, method = @reflection.options[:dependent])
- through_association = @owner.send(@reflection.through_reflection.name)
+ def deletion_scope(records)
+ @owner.send(@reflection.through_reflection.name).where(construct_join_attributes(*records))
+ end
+ def delete_records(records, method = @reflection.options[:dependent])
case method
when :destroy
- records.each do |record|
- through_association.where(construct_join_attributes(record)).destroy_all
- end
+ deletion_scope(records).destroy_all
+ when :nullify
+ deletion_scope(records).update_all(@reflection.source_reflection.foreign_key => nil)
else
- records.each do |record|
- through_association.where(construct_join_attributes(record)).delete_all
- end
+ deletion_scope(records).delete_all
end
end