How to get last N records with activerecord?

前端 未结 14 659
南旧
南旧 2020-12-12 11:43

With :limit in query, I will get first N records. What is the easiest way to get last N records?

14条回答
  •  旧巷少年郎
    2020-12-12 12:16

    In my rails (rails 4.2) project, I use

    Model.last(10) # get the last 10 record order by id
    

    and it works.

提交回复
热议问题