class AzaharaSchema::AggregationAttribute

Attributes

attribute[R]

Public Class Methods

new(model, attribute) click to toggle source
Calls superclass method
# File lib/azahara_schema/aggregation_attribute.rb, line 10
def initialize(model, attribute)
  @attribute = attribute
  super(model, 'sum:'+attribute.name, attribute.type)
end

Public Instance Methods

arel_field() click to toggle source
# File lib/azahara_schema/aggregation_attribute.rb, line 19
def arel_field
  attribute.arel_field.sum
end
searchable?() click to toggle source
# File lib/azahara_schema/aggregation_attribute.rb, line 15
def searchable?
  false
end
value(parent) click to toggle source
# File lib/azahara_schema/aggregation_attribute.rb, line 23
def value(parent)
  val = attribute.attribute.add_join( parent.send(attribute.association.name) ).sum(attribute.arel_field)
  val = BigDecimal.new(val.to_s) unless val.is_a?(BigDecimal)
  val
end