-
Notifications
You must be signed in to change notification settings - Fork 19
Dimension Filters
A dimension filter provides filtering for a report. In SQL-land, this is the WHERE
clause.
Available dimension filters are defined on a FactModel
. They can be implemented via a similar syntax to a Rails scope, link to the fact model's ActiveRecord model's scope, or delegate to ransack.
class TicketFactModel < ActiveReporting::FactModel
dimension_filter :open
dimension_filter :for_category_name, ->(x) { joins(:category).where(categories: {name: x}) }
dimension_filter :subject_cont, :ransack
end
The first example exposes the Ticket.open
scope to the fact model allowing it to be used as a dimension filter.
The second example defines a lambda to be invoked like a Rails scope. It joins against the category
relationship on Ticket
and filters by the category's name.
The third example defines a filter called "subject_cont" and will delegate it to ransack when called.
Only dimension filters defined in the fact model may be used. Whitelisting available filters allows for more control over what the user may filter by. Giving the user full control to call any scope or method from the ActiveRecord model could lead to unexpected results, poor performing queries, or possible security concerns.
If ransack is available, you may flag a fact model to delegate all unknown dimension filters to ransack.
class TicketFactModel < ActiveReporting::FactModel
use_ransack_for_unknown_dimension_filters
end