From 2a42f2b64530d12bf9b409b798d70b244cdaa402 Mon Sep 17 00:00:00 2001 From: Phil Coggins Date: Thu, 17 Dec 2020 15:43:00 -0700 Subject: [PATCH] Adds warning on usage of destroy_async. * Updates documentation of ActiveRecord::Associations::ClassMethods to add warning on using destroy_async as dependent option when the relationship is already backed by foreign key constraints. --- activerecord/lib/active_record/associations.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 7dd421c251..b7545b6e20 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1371,7 +1371,9 @@ module ActiveRecord # # * nil do nothing (default). # * :destroy causes all the associated objects to also be destroyed. - # * :destroy_async destroys all the associated objects in a background job. + # * :destroy_async destroys all the associated objects in a background job. WARNING: Do not use + # this option if the association is backed by foreign key constraints in your database. The foreign key + # constraint actions will occur inside the same transaction that deletes its owner. # * :delete_all causes all the associated objects to be deleted directly from the database (so callbacks will not be executed). # * :nullify causes the foreign keys to be set to +NULL+. Polymorphic type will also be nullified # on polymorphic associations. Callbacks are not executed. @@ -1523,7 +1525,9 @@ module ActiveRecord # # * nil do nothing (default). # * :destroy causes the associated object to also be destroyed - # * :destroy_async causes all the associated object to be destroyed in a background job. + # * :destroy_async causes the associated object to be destroyed in a background job. WARNING: Do not use + # this option if the association is backed by foreign key constraints in your database. The foreign key + # constraint actions will occur inside the same transaction that deletes its owner. # * :delete causes the associated object to be deleted directly from the database (so callbacks will not execute) # * :nullify causes the foreign key to be set to +NULL+. Polymorphic type column is also nullified # on polymorphic associations. Callbacks are not executed.