module Sequel::Plugins::Tree::ClassMethods

Attributes

parent_column[RW]

The symbol for the column containing the value pointing to the parent of the leaf.

tree_order[RW]

The column symbol or array of column symbols on which to order the tree.

Public Instance Methods

freeze() click to toggle source

Should freeze tree order if it is an array when freezing the model class.

Calls superclass method
# File lib/sequel/plugins/tree.rb, line 67
def freeze
  @tree_order.freeze if @tree_order.is_a?(Array)

  super
end
roots() click to toggle source

Returns list of all root nodes (those with no parent nodes).

TreeClass.roots # => [root1, root2]
# File lib/sequel/plugins/tree.rb, line 76
def roots
  roots_dataset.all
end
roots_dataset() click to toggle source

Returns the dataset for retrieval of all root nodes

TreeClass.roots_dataset # => Sequel::Dataset instance
# File lib/sequel/plugins/tree.rb, line 83
def roots_dataset
  ds = where(Sequel.or(Array(parent_column).zip([])))
  ds = ds.order(*tree_order) if tree_order
  ds
end