Skip to content

Commit

Permalink
dependent: :destroy should call destroy_all
Browse files Browse the repository at this point in the history
Commit #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 .
  • Loading branch information
Neeraj Singh committed Mar 12, 2013
1 parent cae93be commit c3829d3
Showing 1 changed file with 3 additions and 2 deletions.
Expand Up @@ -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

Expand Down

2 comments on commit c3829d3

@spastorino
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neerajdotname no tests? 😄

@neerajsingh0101
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.