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
Written by Rashmi
Related protips
2 Responses
Does not works.
over 1 year ago
·
Try it on rails 4.1
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#