Module: Babik::QuerySet::Aggregatable

Included in:
AbstractBase
Defined in:
lib/babik/queryset/mixins/aggregatable.rb

Overview

Functionality related to the aggregation selection

Instance Method Summary collapse

Instance Method Details

#aggregate(agg_functions) ⇒ Hash{symbol: float}

Aggregate a set of objects.

Parameters:

  • agg_functions (Hash{symbol: Babik.agg})

    hash with the different aggregations that will be computed.

Returns:

  • (Hash{symbol: float})

    Result of computing each one of the aggregations.



10
11
12
13
14
# File 'lib/babik/queryset/mixins/aggregatable.rb', line 10

def aggregate(agg_functions)
  @_aggregation = Babik::QuerySet::Aggregation.new(@model, agg_functions)
  select_sql = sql.select
  self.class._execute_sql(select_sql).first.transform_values(&:to_f).symbolize_keys
end