diff options
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 3a0a5165b6..cb64b7887e 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -194,7 +194,7 @@ module ActiveRecord options[:dependent] end - delete(:all, dependent: dependent).tap do + delete_all_with_dependency(dependent).tap do reset loaded! end @@ -259,6 +259,14 @@ module ActiveRecord end end + def delete_all_with_dependency(dependent) + if (loaded? || dependent == :destroy) && dependent != :delete_all + delete_or_destroy(load_target, dependent) + else + delete_records(:all, dependent) + end + end + # Deletes the +records+ and removes them from this association calling # +before_remove+ , +after_remove+ , +before_destroy+ and +after_destroy+ callbacks. # |