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]


151
152
153
# File 'lib/sequel/plugins/tree.rb', line 151

def roots
  roots_dataset.all
end

#roots_datasetObject

Returns the dataset for retrieval of all root nodes

TreeClass.roots_dataset # => Sequel::Dataset instance


158
159
160
161
162
# File 'lib/sequel/plugins/tree.rb', line 158

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