开发者

Why doesn't MyModel.all.each{|m| m.destroy} work as expected?

开发者 https://www.devze.com 2022-12-13 06:52 出处:网络
I want to clear a table in my railsapp 开发者_JAVA百科, without dropping the database and migrating...

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消