Skip to content
This repository
Browse code

re-introduce `select_for_count` private method.

See da9b5d4#commitcomment-3630064 for discussion.
  • Loading branch information...
commit 1f060b670a154ead2eebb90c2b73050febc703d0 1 parent 87c71e5
Yves Senn senny authored

Showing 1 changed file with 10 additions and 5 deletions. Show diff stats Hide diff stats

  1. +10 5 activerecord/lib/active_record/relation/calculations.rb
15 activerecord/lib/active_record/relation/calculations.rb
@@ -207,11 +207,7 @@ def perform_calculation(operation, column_name, options = {})
207 207 end
208 208
209 209 if operation == "count"
210   - if select_values.present?
211   - column_name ||= select_values.join(", ")
212   - else
213   - column_name ||= :all
214   - end
  210 + column_name ||= select_for_count
215 211
216 212 unless arel.ast.grep(Arel::Nodes::OuterJoin).empty?
217 213 distinct = true
@@ -379,6 +375,15 @@ def type_cast_using_column(value, column)
379 375 column ? column.type_cast(value) : value
380 376 end
381 377
  378 + # TODO: refactor to allow non-string `select_values` (eg. Arel nodes).
  379 + def select_for_count
  380 + if select_values.present?
  381 + select_values.join(", ")
  382 + else
  383 + :all
  384 + end
  385 + end
  386 +
382 387 def build_count_subquery(relation, column_name, distinct)
383 388 column_alias = Arel.sql('count_column')
384 389 subquery_alias = Arel.sql('subquery_for_count')

0 comments on commit 1f060b6

Please sign in to comment.
Something went wrong with that request. Please try again.