diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-01-28 06:40:50 -0500 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-01-28 06:40:50 -0500 |
commit | ac0446870f0504958ada7431681e37fffba6391a (patch) | |
tree | 6addd27bd476a31792b3d665ee559aa282b03c2a /activerecord/lib | |
parent | a69281614a7ed6c134d9a799419dd34dd5293a81 (diff) | |
parent | ed15217b054de379d7b0d283d08b71f185fdf2e9 (diff) | |
download | rails-ac0446870f0504958ada7431681e37fffba6391a.tar.gz rails-ac0446870f0504958ada7431681e37fffba6391a.tar.bz2 rails-ac0446870f0504958ada7431681e37fffba6391a.zip |
Merge pull request #23303 from Empact/find-nth-deprecation
Consistently warn that passing an offset to `find_nth` is deprecated
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/finder_methods.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 3cbb12a09d..3f5d6de78a 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -489,20 +489,19 @@ module ActiveRecord end def find_nth(index, offset = nil) + # TODO: once the offset argument is removed we rely on offset_index + # within find_nth_with_limit, rather than pass it in via + # find_nth_with_limit_and_offset + if offset + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Passing an offset argument to find_nth is deprecated, + please use Relation#offset instead. + MSG + end if loaded? @records[index] else - # TODO: once the offset argument is removed we rely on offset_index - # within find_nth_with_limit, rather than pass it in via - # find_nth_with_limit_and_offset - if offset - ActiveSupport::Deprecation.warn(<<-MSG.squish) - Passing an offset argument to find_nth is deprecated, - please use Relation#offset instead. - MSG - else - offset = offset_index - end + offset ||= offset_index @offsets[offset + index] ||= find_nth_with_limit_and_offset(index, 1, offset: offset).first end end |