Method: Babik::QuerySet::AbstractAggregationFunction#prepare

Defined in:
lib/babik/queryset/components/aggregation.rb

#prepare(model, field_name = nil) ⇒ Object

Prepare the aggregation function for a model class and a field

Parameters:

  • model (ActiveRecord::Base)

    model that will be used as origin for association paths.

  • field_name (String, nil) (defaults to: nil)

    Name that will take the computed aggregation operation. If nil, it will take the value <table_alias>__<agg_function>.



54
55
56
57
58
59
# File 'lib/babik/queryset/components/aggregation.rb', line 54

def prepare(model, field_name = nil)
  @model = model
  @selection = Babik::Selection::Path::Factory.build(model, @aggregation_path)
  @field_name = field_name || "#{self.table_alias}__#{SQL_OPERATION.downcase}"
  self
end