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

The enable_active_olap is used to activate your model for performing OLAP queries. It can just be included in your class, and you’re set to go!

class Project < ActiveRecord::Base
  enable_active_olap
end

Passing a block

However, you may use this opportunity to define some dimensions and aggregates for this class by passing a block. These can later be used in your OLAP queries using the symbol that you used as name.

class Project < ActiveRecord::Base
  enable_active_olap do |olap|

    # register a dimension using this syntax
    olap.dimension <:dimension_symbol>, <dimension_definition_hash>

    # register an aggregate function using this syntax
    olap.aggregate <:aggregate_name>, <aggregate_definition>

  end
end

Note that you don’t have to define these dimension here, you can actually pass complete dimension definitions to olap_query. However, it usually is good practice to have all your definitions in one place. You could move them to a separate file if you wish. Moreover, you can use the short-hand names of these dimensions when calling olap_query.

  • See the dimensions page to see how dimension definitions are constructed.
  • See aggregates to see how aggregates are defined and used.
  • See olap_query to see how queries are executed using dimensions and aggregates.
Clone this wiki locally