diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-02-07 16:07:07 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-02-07 16:08:13 +0900 |
commit | 401354b298953a7d83eaef8ab703476991c3e9d4 (patch) | |
tree | 157e39917bb261efdffd83fcec8b26ab038f4931 /activerecord/lib/active_record | |
parent | 383c4de2df17cd4168274c96e379292262f29189 (diff) | |
download | rails-401354b298953a7d83eaef8ab703476991c3e9d4.tar.gz rails-401354b298953a7d83eaef8ab703476991c3e9d4.tar.bz2 rails-401354b298953a7d83eaef8ab703476991c3e9d4.zip |
Revert "Remove useless `column_alias` in `subquery_for_count`"
This reverts commit 28977f1fa3d7b15c1608174a165e60b71ddf3995.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index e8aba02611..35c670f1a1 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -364,14 +364,15 @@ module ActiveRecord end def build_count_subquery(relation, column_name, distinct) + column_alias = Arel.sql("count_column") subquery_alias = Arel.sql("subquery_for_count") - aliased_column = aggregate_column(column_name == :all ? "1" : column_name) + aliased_column = aggregate_column(column_name == :all ? 1 : column_name).as(column_alias) relation.select_values = [aliased_column] subquery = relation.arel.as(subquery_alias) sm = Arel::SelectManager.new relation.engine - select_value = operation_over_aggregate_column(Arel.star, "count", distinct) + select_value = operation_over_aggregate_column(column_alias, "count", distinct) sm.project(select_value).from(subquery) end end |