has_many :dependent => :destroy and association callbacks

Today I noticed that calling object.collection.destroy_all leads to
calling association callbacks like ex. :before_remove but
object.destroy does not call those callbacks when configured
with :dependent => :destroy option.

You can find that hbtm uses collection.clear which under the hoods
calls collection.destroy_all however has_many uses the metod
configure_dependency_for_has_many to setup the hooks (
which iterates over the collection and sends destroy() to every object

I think it could be a good thing to make has_many behave more like
hbtm and just use collection.destroy_all . This way also the
association callbacks would get called. Also probably the optimization
fix with counter_method could probably be move to the call in


I am working on refactoring this section of the code at the moment
actually, and this problem will be fixed when I'm done.


I'm glad to hear it.

Robert Pankowecki