Posts Tagged ‘patch’
destroy_all with conditions November 3rd, 2008
In a has_many relationship, there should be a way to add conditions to destroy in order to eliminate an explicit find.
@post.comments.find(:all, :conditions => "name LIKE 'stupid%'").each {|record| record.destroy }
With a patch I recently submitted to Rails core, you can now trim this line into:
@post.comments.destroy_all "name LIKE 'stupid%'"
Jump on over to Lighthouse bugtracker and try out the patch.
Tags: destroy_all, patch, Rails
Posted in Development, Rails | Comments (0)


