module Mongoid::Tree::ClassMethods
This module implements class methods that will be available on the document that includes Mongoid::Tree
Public Instance Methods
leaves()
click to toggle source
Returns all leaves (be careful, currently involves two queries)
@example
Node.leaves
@return [Mongoid::Criteria] Mongoid
criteria to retrieve all leave nodes
# File lib/mongoid/tree.rb, line 154 def leaves where(:_id.nin => only(:parent_id).collect(&:parent_id)) end
root()
click to toggle source
Returns the first root document
@example
Node.root
@return [Mongoid::Document] The first root document
# File lib/mongoid/tree.rb, line 132 def root roots.first end
roots()
click to toggle source
Returns all root documents
@example
Node.roots
@return [Mongoid::Criteria] Mongoid
criteria to retrieve all root documents
# File lib/mongoid/tree.rb, line 143 def roots where(:parent_id => nil) end