Flowdock
execute_simple_calculation(operation, column_name, distinct) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# 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
Register or log in to add new notes.