Skip to content
wvanbergen edited this page Sep 12, 2010 · 9 revisions

The olap_query-method must be called with a list of dimensions_, which can be defined using a special syntax. Dimension can be defined in the block that is passed to the @enable_activeolap@ class method. After registering, these dimension will be available to your OLAP queries using the symbol that you used to register it.

It is recommended to register dimensions, but is is not required. Registering a dimension basically means that it is safe to use and will yield meaningful results according to the person who registers it. You can pass complete dimension definitions (usually hashes) to an olap_query-call if you do not want to register them beforehand.

There are three types of dimensions that can be defined:

  • Simple dimensions using pivot fields
  • Custom dimensions
  • Time dimensions

Simple dimensions

A simple dimension just uses the value of a given field to categorize records. Examples:

class Project < ActiveRecord::Base 
  enable_active_olap do |olap
    # create a dimension using the status field
    olap.dimension :status

    # create a dimension using the project_type field, called :type
    olap.dimension :type, :project_type

    # Even more verbose. Every element of the hash (except @field@) will be available
    # in the @info@-method of the dimension, which returns a hash as well.
    olap.dimension :type_again, {:field => :project_type, :name => "Project type dimension"}
  end
end

Custom dimensions

Time dimensions