Method: ActiveWarehouse::Fact.dimension

Defined in:
lib/active_warehouse/fact.rb

.dimension(association_id, options = {}) ⇒ Object

Acts as an alias for belongs_to, yet marks this relationship as a dimension. You must call dimension instead of belongs_to. Accepts same options as belongs_to.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_warehouse/fact.rb', line 27

def dimension(association_id, options = {})
  options[:class_name] ||= "#{association_id}Dimension".classify
  options[:foreign_key] ||= "#{association_id}_id"
  slowly_changing_over = options.delete(:slowly_changing)
  belongs_to association_id, options
  dimension_relationship = reflections[association_id]
  
  if slowly_changing_over
    if !dimensions.include?(slowly_changing_over)
      raise "No dimension specified with name '#{slowly_changing_over}' in fact '#{self.name}', specify it first with dimension macro"
    end
    dimension_relationship.slowly_changing_over = dimension_relationships[slowly_changing_over]
  end
  
  dimension_relationships[association_id] = dimension_relationship
end