mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Distinct with order #count regression
This commit is contained in:
parent
065c1fae12
commit
5120bc90c2
2 changed files with 9 additions and 1 deletions
|
@ -132,7 +132,7 @@ module ActiveRecord
|
|||
if has_include?(column_name)
|
||||
relation = apply_join_dependency
|
||||
|
||||
if operation.to_s.downcase == "count" && !distinct_value
|
||||
if operation.to_s.downcase == "count"
|
||||
relation.distinct!
|
||||
# PostgreSQL: ORDER BY expressions must appear in SELECT list when using DISTINCT
|
||||
if (column_name == :all || column_name.nil?) && select_values.empty?
|
||||
|
|
|
@ -242,6 +242,14 @@ class CalculationsTest < ActiveRecord::TestCase
|
|||
assert_queries(1) { assert_equal 11, posts.count(:all) }
|
||||
end
|
||||
|
||||
def test_count_with_eager_loading_and_custom_order_and_distinct
|
||||
posts = Post.includes(:comments).order("comments.id").distinct
|
||||
assert_queries(1) { assert_equal 11, posts.count }
|
||||
assert_queries(1) { assert_equal 11, posts.count(:all) }
|
||||
assert_queries(1) { assert_equal 11, posts.size }
|
||||
assert_queries(1) { assert_equal 11, posts.load.size }
|
||||
end
|
||||
|
||||
def test_distinct_count_all_with_custom_select_and_order
|
||||
accounts = Account.distinct.select("credit_limit % 10").order(Arel.sql("credit_limit % 10"))
|
||||
assert_queries(1) { assert_equal 3, accounts.count(:all) }
|
||||
|
|
Loading…
Reference in a new issue