class Babik::QuerySet::Aggregation

A set of aggregation operations

Attributes

functions[R]
model[R]

Public Class Methods

new(model, functions) click to toggle source

Construct a new aggregation @param model [Class] class that inherits from ActiveRecord::Base. @param functions [Array<Avg, Max, Min, Sum>] array of aggregation functions.

# File lib/babik/queryset/components/aggregation.rb, line 15
def initialize(model, functions)
  @model = model
  @functions = []
  functions.each do |field_name, function|
    @functions << function.prepare(@model, field_name)
  end
end

Public Instance Methods

left_joins_by_alias() click to toggle source

Return the joins grouped by alias @return [Hash{alias: Babik::QuerySet::Join}] Hash where the value is the alias of the table and the value is a Babik::Join

# File lib/babik/queryset/components/aggregation.rb, line 25
def left_joins_by_alias
  left_joins_by_alias = {}
  @functions.each do |function|
    left_joins_by_alias.merge!(function.left_joins_by_alias)
  end
  left_joins_by_alias
end
sql() click to toggle source

Return aggregation SQL @return [String] Aggregation SQL

# File lib/babik/queryset/components/aggregation.rb, line 35
def sql
  @functions.map(&:sql).join(', ')
end