Module: Hierarchy

Extended by:
ActiveSupport::Concern
Defined in:
lib/hierarchy.rb,
lib/hierarchy/node.rb,
lib/hierarchy/index_path.rb

Overview

Adds a tree structure to a model. This is very similar to @acts_as_nested_set@ but uses the PostgreSQL-specific @ltree@ feature for schema storage.

Your model must have a @path@ field of type @ltree@. This field will be a period-delimited list of IDs of records above this one in the hierarchy. In addition, you should also consider the following indexes:

<pre> CREATE INDEX index1 ON table USING gist(path) CREATE INDEX index2 ON table USING btree(path) </pre>

replacing @table@ with your table and @index1@/@index2@ with appropriate names for these indexes.

Examples:

class MyModel < ActiveRecord::Base
  include Hierarchy
end

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: IndexPath, Node