aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
authorBrian Christian <brchristian@gmail.com>2016-02-27 11:39:02 -0800
committerBrian Christian <brchristian@gmail.com>2016-02-27 11:39:02 -0800
commit7ea1da65d7e14e420cdb5957618db37f092badda (patch)
tree7967816183ac36c952052575dbd8b3a89bdb335b /activerecord/lib/active_record/relation/finder_methods.rb
parentf5a9c5bd40af9889ce9ed95a20fe530142532d1b (diff)
downloadrails-7ea1da65d7e14e420cdb5957618db37f092badda.tar.gz
rails-7ea1da65d7e14e420cdb5957618db37f092badda.tar.bz2
rails-7ea1da65d7e14e420cdb5957618db37f092badda.zip
refactor AR second_to_last to use array methods
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 245976dc2b..960c409d4b 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -565,7 +565,12 @@ module ActiveRecord
if loaded?
@records[-index]
else
- reverse_order.offset(index-1).first
+ 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),
+ # or by using a combination of reverse_order, limit, and offset,
+ # e.g., reverse_order.offset(index-1).first
end
end