1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Raises IrreversibleOrderError when using last with an irreversible order

This commit is contained in:
Rafael Mendonça França 2016-12-29 13:14:00 -05:00
parent 0944182ad7
commit 931b4b4d64
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
3 changed files with 6 additions and 9 deletions

View file

@ -1,3 +1,8 @@
* 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*

View file

@ -152,14 +152,6 @@ module ActiveRecord
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

View file

@ -592,7 +592,7 @@ class FinderTest < ActiveRecord::TestCase
end
def test_last_with_irreversible_order
assert_deprecated do
assert_raises(ActiveRecord::IrreversibleOrderError) do
Topic.order("coalesce(author_name, title)").last
end
end