diff options
author | Ben Woosley <ben.woosley@gmail.com> | 2016-01-27 21:14:31 -0800 |
---|---|---|
committer | Ben Woosley <ben.woosley@gmail.com> | 2016-01-27 21:19:58 -0800 |
commit | ed15217b054de379d7b0d283d08b71f185fdf2e9 (patch) | |
tree | 36f52db1cc990d507b207f9412c65d132802fa1a /activerecord | |
parent | 6381d080789dd2ea613bc8e57d2b6fee7210f1c3 (diff) | |
download | rails-ed15217b054de379d7b0d283d08b71f185fdf2e9.tar.gz rails-ed15217b054de379d7b0d283d08b71f185fdf2e9.tar.bz2 rails-ed15217b054de379d7b0d283d08b71f185fdf2e9.zip |
Consistently warn that passing an offset to `find_nth` is deprecated
@bogdan pointed out that a `loaded?` relation would not warn that the supplied
offset would be removed. This fixes that oversight.
https://github.com/rails/rails/commit/16a476e4f8f802774ae7c8dca2e59f4e672dc591#commitcomment-15706834
Although this second argument is probably not widely used, and would be
ignored anyway in the loaded? case, this could protect callers from gotchas.
[Ben Woosley & Victor Kmita]
Diffstat (limited to 'activerecord')
-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 |