Why doesn't MyModel.all.each{|m| m.destroy} work as expected?
I want to clear a table in my railsapp 开发者_JAVA百科, without dropping the database and migrating...
MyModel.all.each{|m| m.destroy}
I would expect this code to delete every record in the my_model table, but this is not happening... using Rails 2.3.4 + MySQL 5.1
EDIT: the issue was based on the plugin better_nested_set which didn't allow me to delete the entries in that order
MyModel.delete_all
worked on the other hand , maybe because it executes truncate on the database (?)
Use MyModel.destroy_all
to delete all the records for your model.
精彩评论