开发者

How do I keep the last 10 entries and delete the rest?

User has more than 20 records in a table. I only want to keep开发者_如何学Python the last 10 entries. Which means I want to delete the rest.

I want to do this for each user in that table as well.

How should I go about this?


Item.destroy(Item.order('created_at').all.last(10).map(&:id))

There's probably a less expensive way to do it, but that should work for you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜