mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23303 from Empact/find-nth-deprecation
Consistently warn that passing an offset to `find_nth` is deprecated
This commit is contained in:
commit
ac0446870f
1 changed files with 10 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue