aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-01-07 12:42:37 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-01-07 12:52:59 +0900
commit68754d37706f11ca363b3108eda10749b9957817 (patch)
treec874adc065384214f1876ce1c3ae7e22cbff52d9 /activerecord/lib/active_record/relation/finder_methods.rb
parenta194c527fa7b16840fd1b1250dc9f624c6536546 (diff)
downloadrails-68754d37706f11ca363b3108eda10749b9957817.tar.gz
rails-68754d37706f11ca363b3108eda10749b9957817.tar.bz2
rails-68754d37706f11ca363b3108eda10749b9957817.zip
Fix `last` with `offset` to behave consistently with loaded relation
Currently `last` with `offset` behaves incorrectly because `offset` can not be reversed like `limit`. Therefore, `offset` should also be handled like `limit`.
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index b61e65cfb3..4bf346a512 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -148,7 +148,7 @@ module ActiveRecord
#
# [#<Person id:4>, #<Person id:3>, #<Person id:2>]
def last(limit = nil)
- return find_last(limit) if loaded? || limit_value
+ return find_last(limit) if loaded? || has_limit_or_offset?
result = ordered_relation.limit(limit)
result = result.reverse_order!