Last Updated: February 25, 2016
·
1.022K
· raysrashmi

second to fifth methods for ActiveRecord Model

User.first #=>SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1

We all know this

But now in 4.1 ActiveSupport (first, second, third, fourth, and fifth) methods are also available as full-fledged finders in ActiveRecord

User.second #=> SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1 OFFSET 1

User.third #=>SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1 OFFSET 2

User.fourth #=>SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1 OFFSET 3

User.fifth #=>SELECT  "users".* FROM "users"   ORDER BY "users"."id" ASC LIMIT 1 OFFSET 4

2 Responses
Add your response

Does not works.

over 1 year ago ·

Try it on rails 4.1

over 1 year ago ·