Browse files

dependent: :destroy should call destroy_all

Commit #9668 shows warning
when `delete_all` is invoked with `:dependent` option

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 .
  • Loading branch information...
1 parent cae93be commit c3829d31866870e852a64f8a1236f3287d41783b Neeraj Singh committed Mar 12, 2013
Showing with 3 additions and 2 deletions.
  1. +3 −2 activerecord/lib/active_record/associations/has_many_association.rb
5 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
+ destroy_all
+ else
+ delete_all
- delete_all

2 comments on commit c3829d3

Ruby on Rails member

@neerajdotname no tests? 😄

Ruby on Rails member

@spastorino There was no change in functionality.

@post.comments.destroy_all was calling delete_all. And @post.comments.delete_all also calls delete_all.

Since we added warning message in delete_all now Post.destroy_all started showing warnings. This was the fix for not displaying the warning for Post.destroy_all .

Please sign in to comment.