rails/rails — pull request #13757 by terracatta (2014-01-18 23:39:52+00:00)
Title: Ensure #second (and others) acts like #first AR finder

This PR addresses issue #13743 where the ordinal ActiveSupport Array extentions were not assuming a default order like first was.

As suggested by @dhh this commit bring the famous ordinal Array instance methods defined
in ActiveSupport into ActiveRecord as fully-fledged finders.

These finders ensure a default ascending order of the table's primary
key, and utilize the OFFSET SQL verb to locate the user's desired
record. If an offset is defined in the query, calling #second adds
to the offset to get the actual desired record.

Example:

User.all.second

# Before
# => 'SELECT "users".* FROM "users"'

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

User.offset(3).second

# Before
# => 'SELECT "users".* FROM "users"'

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