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:
parent
0944182ad7
commit
931b4b4d64
3 changed files with 6 additions and 9 deletions
|
@ -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*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue