Raises IrreversibleOrderError when using last with an irreversible order

上级 0944182a
* Raises `ActiveRecord::IrreversibleOrderError` when using `last` with an irreversible
order.
*Rafael Mendonça França*
* Raises when a through association has an ambiguous reflection name.
*Rafael Mendonça França*
......
......@@ -152,14 +152,6 @@ def last(limit = nil)
result = result.reverse_order!
limit ? result.reverse : result.first
rescue ActiveRecord::IrreversibleOrderError
ActiveSupport::Deprecation.warn(<<-WARNING.squish)
Finding a last element by loading the relation when SQL ORDER
can not be reversed is deprecated.
Rails 5.1 will raise ActiveRecord::IrreversibleOrderError in this case.
Please call `to_a.last` if you still want to load the relation.
WARNING
find_last(limit)
end
# Same as #last but raises ActiveRecord::RecordNotFound if no record
......
......@@ -592,7 +592,7 @@ def test_last_on_loaded_relation_should_not_use_sql
end
def test_last_with_irreversible_order
assert_deprecated do
assert_raises(ActiveRecord::IrreversibleOrderError) do
Topic.order("coalesce(author_name, title)").last
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册