From c3829d31866870e852a64f8a1236f3287d41783b Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Mon, 11 Mar 2013 20:50:22 -0400 Subject: [PATCH] dependent: :destroy should call destroy_all Commit https://github.com/rails/rails/pull/9668 shows warning when `delete_all` is invoked with `:dependent` option `:destroy`. Unfortunately invoking `Post.destroy_all` invokes `post.comments.delete_all` as part of `has_many` callbacks. This commit ensures that instead `post.comments.destroy_all` is invoked and in the process no warning is generated. See issue #9567 for details . --- .../lib/active_record/associations/has_many_association.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index f59565ae77e0c..b7b4d7e3ae159 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -23,9 +23,10 @@ def handle_dependency if options[:dependent] == :destroy # No point in executing the counter update since we're going to destroy the parent anyway load_target.each(&:mark_for_destruction) + destroy_all + else + delete_all end - - delete_all end end