> When I call destoy_all on a model with a where clause AR iterates > though each record in the recordset and calls destroy on each item. > This seems highly inefficient to me. Wouldn't it be better to call > delete from child records where foreign_id in (parent ids)? > > In other words shouldn't destroy all destroy all the children for all > the items in one shot?
No. Destroy has to instantiate each object prior to actually removing it from the database in order to run any before/after destroy call backs. You can speed things up if you don't need this by tweaking the :dependent option to has_many so that it will simply use SQL's DELETE on the child objects... but that of course won't run any callbacks (your own, or Rail's counter cache, etc.) > I am having to manually do destroy all on my children when I have > large number of records to delete so I am wondering if there is a more > elegant way of handling this. > > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

