diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-07-14 18:27:00 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-07-14 21:00:39 +0200 |
commit | 648afea0e4addcaaf6da31cba78b94d7681706a4 (patch) | |
tree | 1e8fe87e2538105478c9353b6a8c2fe16f36ccf5 /activerecord/lib/active_record/relation | |
parent | b5e851e90bd1382fa1875d0a9fb2f997b817c25e (diff) | |
download | rails-648afea0e4addcaaf6da31cba78b94d7681706a4.tar.gz rails-648afea0e4addcaaf6da31cba78b94d7681706a4.tar.bz2 rails-648afea0e4addcaaf6da31cba78b94d7681706a4.zip |
re-introduce `select_for_count` private method.
See https://github.com/rails/rails/commit/da9b5d4a8435b744fcf278fffd6d7f1e36d4a4f2#commitcomment-3630064 for discussion.
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/calculations.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 3b24ed6754..52a538e5b5 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -189,11 +189,7 @@ module ActiveRecord distinct = self.distinct_value if operation == "count" - if select_values.present? - column_name ||= select_values.join(", ") - else - column_name ||= :all - end + column_name ||= select_for_count unless arel.ast.grep(Arel::Nodes::OuterJoin).empty? distinct = true @@ -361,6 +357,15 @@ module ActiveRecord column ? column.type_cast(value) : value end + # TODO: refactor to allow non-string `select_values` (eg. Arel nodes). + def select_for_count + if select_values.present? + select_values.join(", ") + else + :all + end + end + def build_count_subquery(relation, column_name, distinct) column_alias = Arel.sql('count_column') subquery_alias = Arel.sql('subquery_for_count') |