Skip to content

Commit

Permalink
Restore an ability that reorder with first taking non-determinist…
Browse files Browse the repository at this point in the history
…ic result

Actually, `first` taking non-deterministic result is considered a bug to
me. But changing the behavior should not be happened in rc2.

I've restored the behavior for 6.0, and then will deprecate that in 6.1.

Fixes rails#36802.
  • Loading branch information
kamipo committed Aug 9, 2019
1 parent f57aac4 commit 80c1f15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -372,7 +372,7 @@ def reorder(*args)

# Same as #reorder but operates on relation in-place instead of copying.
def reorder!(*args) # :nodoc:
preprocess_order_args(args)
preprocess_order_args(args) unless args.all?(&:blank?)

self.reordering_value = true
self.order_values = args
Expand Down
14 changes: 14 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -1737,6 +1737,20 @@ def test_reverse_order_with_reorder_nil_removes_the_order
assert_nil relation.order_values.first
end

def test_reorder_with_first
sql_log = capture_sql do
assert Post.order(:title).reorder(nil).first
end
assert sql_log.all? { |sql| !/order by/i.match?(sql) }, "ORDER BY was used in the query: #{sql_log}"
end

def test_reorder_with_take
sql_log = capture_sql do
assert Post.order(:title).reorder(nil).take
end
assert sql_log.all? { |sql| !/order by/i.match?(sql) }, "ORDER BY was used in the query: #{sql_log}"
end

def test_presence
topics = Topic.all

Expand Down

0 comments on commit 80c1f15

Please sign in to comment.