Module: Sequel::Plugins::Tree::DatasetMethods

Defined in:
lib/sequel/plugins/tree.rb

Instance Method Summary collapse

Instance Method Details

#rootsObject

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

TreeClass.roots # => [root1, root2]

146
147
148
# File 'lib/sequel/plugins/tree.rb', line 146

def roots
  roots_dataset.all
end

#roots_datasetObject

Returns the dataset for retrieval of all root nodes

TreeClass.roots_dataset # => Sequel::Dataset instance

153
154
155
156
157
# File 'lib/sequel/plugins/tree.rb', line 153

def roots_dataset
  ds = where(Sequel.or(Array(model.parent_column).zip([])))
  ds = ds.order(*model.tree_order) if model.tree_order
  ds
end