Activerecord:找到表

时间:2017-12-09 01:28:01

标签: ruby-on-rails ruby postgresql activerecord

{ topic: "Foo", opportunity: Opportunity.limit(15)[0] },
{ topic: "Foo", opportunity: Opportunity.limit(15)[2] },
{ topic: "Foo", opportunity: Opportunity.limit(15)[7] },
{ topic: "Foo", opportunity: Opportunity.limit(15)[9] },
{ topic: "Foo", opportunity: Opportunity.limit(15)[11]}

而不是Opportunity.limit(15)[n],活动记录是否提供任何便利功能?

1 个答案:

答案 0 :(得分:3)

您正在寻找offset

另请注意,未将order传递给查询并不能保证查询将返回主键排序的实例。所以最好传递一个明确的order

Opportunity.order(:id).limit(1).offset(2)