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 (
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations.rb#L1000
)
which iterates over the collection and sends destroy() to every object
(https://github.com/rails/rails/blob/master/activerecord/lib/
active_record/associations.rb#L1625)

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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-c...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to