提交 385799a4 编写于 作者: A Andrew White 提交者: GitHub

Merge pull request #25274 from kamipo/fix_find_nth_with_limit_value

Fix `find_nth` with `limit_value`
......@@ -147,7 +147,7 @@ def first!
def last(limit = nil)
return find_last(limit) if loaded? || limit_value
result = limit(limit || 1)
result = limit(limit)
result.order!(arel_attribute(primary_key)) if order_values.empty? && primary_key
result = result.reverse_order!
......@@ -536,8 +536,12 @@ def find_nth_with_limit(index, limit)
self
end
relation = relation.offset(offset_index + index) unless index.zero?
relation.limit(limit).to_a
if limit_value.nil? || index < limit_value
relation = relation.offset(offset_index + index) unless index.zero?
relation.limit(limit).to_a
else
[]
end
end
end
......
......@@ -497,7 +497,7 @@ def test_second_to_last
assert_nil Topic.offset(5).second_to_last
#test with limit
# assert_nil Topic.limit(1).second # TODO: currently failing
assert_nil Topic.limit(1).second
assert_nil Topic.limit(1).second_to_last
end
......@@ -526,9 +526,9 @@ def test_third_to_last
assert_nil Topic.offset(5).third_to_last
# test with limit
# assert_nil Topic.limit(1).third # TODO: currently failing
assert_nil Topic.limit(1).third
assert_nil Topic.limit(1).third_to_last
# assert_nil Topic.limit(2).third # TODO: currently failing
assert_nil Topic.limit(2).third
assert_nil Topic.limit(2).third_to_last
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册