diff options
author | Brian Christian <brchristian@gmail.com> | 2018-01-09 11:28:30 -0800 |
---|---|---|
committer | Brian Christian <brchristian@gmail.com> | 2018-01-09 11:28:30 -0800 |
commit | b75a67cdef06cbf0a5a4feb1be9c74f31b89b28a (patch) | |
tree | b58b6b49c5abc95983b1885df1663d63fb44c399 /activerecord/lib/active_record/relation | |
parent | baa88b8ddff59b10b8e98eeee7503e2416da8abe (diff) | |
download | rails-b75a67cdef06cbf0a5a4feb1be9c74f31b89b28a.tar.gz rails-b75a67cdef06cbf0a5a4feb1be9c74f31b89b28a.tar.bz2 rails-b75a67cdef06cbf0a5a4feb1be9c74f31b89b28a.zip |
resolve inconsistencies between first and to_a.first with limit
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index e61cacf6a7..50d0f14b98 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -532,7 +532,11 @@ module ActiveRecord else relation = ordered_relation - if limit_value.nil? || index < limit_value + if limit_value + limit = [limit_value - index, limit].min + end + + if limit > 0 relation = relation.offset(offset_index + index) unless index.zero? relation.limit(limit).to_a else |