Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
66632308
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
66632308
编写于
8月 15, 2016
作者:
K
Kasper Timm Hansen
提交者:
GitHub
8月 15, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #26167 from kamipo/remove_find_nth_with_limit_and_offset
Remove `find_nth_with_limit_and_offset` private method
上级
a3c2b04f
c9220bfa
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
34 deletion
+13
-34
activerecord/lib/active_record/relation/finder_methods.rb
activerecord/lib/active_record/relation/finder_methods.rb
+13
-34
未找到文件。
activerecord/lib/active_record/relation/finder_methods.rb
浏览文件 @
66632308
...
...
@@ -117,7 +117,7 @@ def take!
#
def
first
(
limit
=
nil
)
if
limit
find_nth_with_limit
_and_offset
(
0
,
limit
,
offset:
offset_index
)
find_nth_with_limit
(
0
,
limit
)
else
find_nth
0
end
...
...
@@ -520,22 +520,8 @@ def find_take
end
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
offset
||=
offset_index
@offsets
[
offset
+
index
]
||=
find_nth_with_limit_and_offset
(
index
,
1
,
offset:
offset
).
first
end
def
find_nth
(
index
)
@offsets
[
offset_index
+
index
]
||=
find_nth_with_limit
(
index
,
1
).
first
end
def
find_nth!
(
index
)
...
...
@@ -543,16 +529,18 @@ def find_nth!(index)
end
def
find_nth_with_limit
(
index
,
limit
)
# TODO: once the offset argument is removed from find_nth,
# find_nth_with_limit_and_offset can be merged into this method.
relation
=
if
order_values
.
empty?
&&
primary_key
order
(
arel_attribute
(
primary_key
).
asc
)
if
loaded?
records
[
index
,
limit
]
else
self
end
relation
=
if
order_values
.
empty?
&&
primary_key
order
(
arel_attribute
(
primary_key
).
asc
)
else
self
end
relation
=
relation
.
offset
(
index
)
unless
index
.
zero?
relation
.
limit
(
limit
).
to_a
relation
=
relation
.
offset
(
offset_index
+
index
)
unless
index
.
zero?
relation
.
limit
(
limit
).
to_a
end
end
def
find_nth_from_last
(
index
)
...
...
@@ -576,15 +564,6 @@ def find_nth_from_last(index)
private
def
find_nth_with_limit_and_offset
(
index
,
limit
,
offset
:)
# :nodoc:
if
loaded?
records
[
index
,
limit
]
else
index
+=
offset
find_nth_with_limit
(
index
,
limit
)
end
end
def
find_last
(
limit
)
limit
?
records
.
last
(
limit
)
:
records
.
last
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录