简体   繁体   中英

Deleting top N records in Rails 4

I can't believe I can't find how to do this, but I'm having trouble deleting the top 20 records in Rails 4.

I'm trying variations of this:

Comment.all(:order=> 'id asc', :limit => 20).delete

or

Comment.find(:all, :order => 'id asc', :limit => 20).delete

I'm getting this error:

ArgumentError: wrong number of arguments (1 for 0)

What am I doing wrong?

您需要使用destroy_all

Comment.order('id').limit(20).destroy_all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM