1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

default second_to_last to primary_key index if no order supplied

This commit is contained in:
Brian Christian 2016-02-27 11:52:52 -08:00
parent 7ea1da65d7
commit f9ddfc3b4b

View file

@ -565,7 +565,13 @@ module ActiveRecord
if loaded?
@records[-index]
else
to_a[-index]
relation = if order_values.empty? && primary_key
order(arel_attribute(primary_key).asc)
else
self
end
relation.to_a[-index]
# TODO: can be made more performant on large result sets by
# for instance, last(index)[-index] (which would require
# refactoring the last(n) finder method to make test suite pass),