method
execute_simple_calculation
v3.0.0 -
Show latest stable
- Class:
ActiveRecord::Calculations
execute_simple_calculation(operation, column_name, distinct)private
No documentation available.
# File activerecord/lib/active_record/relation/calculations.rb, line 187
def execute_simple_calculation(operation, column_name, distinct) #:nodoc:
column = if @klass.column_names.include?(column_name.to_s)
Arel::Attribute.new(@klass.unscoped, column_name)
else
Arel::SqlLiteral.new(column_name == :all ? "*" : column_name.to_s)
end
# Postgresql doesn't like ORDER BY when there are no GROUP BY
relation = except(:order).select(operation == 'count' ? column.count(distinct) : column.send(operation))
type_cast_calculated_value(@klass.connection.select_value(relation.to_sql), column_for(column_name), operation)
end