mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ignore order when doing count.
This is necessary because Postgresql doesn't play nice with ORDER BY and no GROUP BY. Fixes #14621.
This commit is contained in:
parent
013b7c19c8
commit
bbad7523f0
2 changed files with 15 additions and 1 deletions
|
@ -231,7 +231,7 @@ module ActiveRecord
|
|||
|
||||
def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
|
||||
# Postgresql doesn't like ORDER BY when there are no GROUP BY
|
||||
relation = reorder(nil)
|
||||
relation = unscope(:order)
|
||||
|
||||
column_alias = column_name
|
||||
|
||||
|
|
|
@ -387,6 +387,20 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
assert_raise(ArgumentError) { Account.count(1, 2, 3) }
|
||||
end
|
||||
|
||||
def test_count_with_order
|
||||
assert_equal 6, Account.order(:credit_limit).count
|
||||
end
|
||||
|
||||
def test_count_with_reverse_order
|
||||
assert_equal 6, Account.order(:credit_limit).reverse_order.count
|
||||
end
|
||||
|
||||
def test_count_with_where_and_order
|
||||
assert_equal 1, Account.where(firm_name: '37signals').count
|
||||
assert_equal 1, Account.where(firm_name: '37signals').order(:firm_name).count
|
||||
assert_equal 1, Account.where(firm_name: '37signals').order(:firm_name).reverse_order.count
|
||||
end
|
||||
|
||||
def test_should_sum_expression
|
||||
# Oracle adapter returns floating point value 636.0 after SUM
|
||||
if current_adapter?(:OracleAdapter)
|
||||
|
|
Loading…
Reference in a new issue