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:
parent
7ea1da65d7
commit
f9ddfc3b4b
1 changed files with 7 additions and 1 deletions
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue