Skip to content

Commit 773eeec

Browse files
committed
Remove deprecated support to Model.reorder(nil).first to search using non-deterministic order.
1 parent 98f608b commit 773eeec

File tree

5 files changed

+14
-24
lines changed

5 files changed

+14
-24
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated support to `Model.reorder(nil).first` to search using non-deterministic order.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated rake tasks:
26

37
* `db:schema:load_if_ruby`

activerecord/lib/active_record/relation/finder_methods.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ def find_sole_by(arg, *args)
140140
# Person.first(3) # returns the first three objects fetched by SELECT * FROM people ORDER BY people.id LIMIT 3
141141
#
142142
def first(limit = nil)
143-
check_reorder_deprecation unless loaded?
144-
145143
if limit
146144
find_nth_with_limit(0, limit)
147145
else
@@ -390,17 +388,6 @@ def raise_record_not_found_exception!(ids = nil, result_size = nil, expected_siz
390388
end
391389

392390
private
393-
def check_reorder_deprecation
394-
if !order_values.empty? && order_values.all?(&:blank?)
395-
blank_value = order_values.first
396-
ActiveSupport::Deprecation.warn(<<~MSG.squish)
397-
`.reorder(#{blank_value.inspect})` with `.first` / `.first!` no longer
398-
takes non-deterministic result in Rails 7.0.
399-
To continue taking non-deterministic result, use `.take` / `.take!` instead.
400-
MSG
401-
end
402-
end
403-
404391
def construct_relation_for_exists(conditions)
405392
conditions = sanitize_forbidden_attributes(conditions)
406393

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,14 @@ def in_order_of(column, values)
448448
# generates a query with 'ORDER BY id ASC, name ASC'.
449449
def reorder(*args)
450450
check_if_method_has_arguments!(__callee__, args) do
451-
sanitize_order_arguments(args) unless args.all?(&:blank?)
451+
sanitize_order_arguments(args)
452452
end
453453
spawn.reorder!(*args)
454454
end
455455

456456
# Same as #reorder but operates on relation in-place instead of copying.
457457
def reorder!(*args) # :nodoc:
458-
preprocess_order_args(args) unless args.all?(&:blank?)
458+
preprocess_order_args(args)
459459
args.uniq!
460460
self.reordering_value = true
461461
self.order_values = args

activerecord/test/cases/relations_test.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,17 +1821,14 @@ def test_reverse_order_with_reorder_nil_removes_the_order
18211821
end
18221822

18231823
def test_reorder_with_first
1824+
post = nil
1825+
18241826
sql_log = capture_sql do
1825-
message = <<~MSG.squish
1826-
`.reorder(nil)` with `.first` / `.first!` no longer
1827-
takes non-deterministic result in Rails 7.0.
1828-
To continue taking non-deterministic result, use `.take` / `.take!` instead.
1829-
MSG
1830-
assert_deprecated(message) do
1831-
assert Post.order(:title).reorder(nil).first
1832-
end
1827+
post = Post.order(:title).reorder(nil).first
18331828
end
1834-
assert sql_log.all? { |sql| !/order by/i.match?(sql) }, "ORDER BY was used in the query: #{sql_log}"
1829+
1830+
assert_equal posts(:welcome), post
1831+
assert sql_log.any? { |sql| /order by/i.match?(sql) }, "ORDER BY was not used in the query: #{sql_log}"
18351832
end
18361833

18371834
def test_reorder_with_take

guides/source/7_0_release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Please refer to the [Changelog][active-record] for detailed changes.
137137
* `db:test:load_structure`
138138
* `db:test:load_structure:#{name}`
139139

140+
* Remove deprecated support to `Model.reorder(nil).first` to search using non-deterministic order.
141+
140142
### Deprecations
141143

142144
### Notable changes

0 commit comments

Comments
 (0)