module Mongoid::SleepingKingStudios::HasTree::ClassMethods
Class methods added to the base class via extend.
Public Instance Methods
has_tree(**options)
click to toggle source
@overload has_tree
(options = {})
Sets up the relations necessary for the tree structure. @param [Hash] options The options for the relation and the concern as a whole. @option options [Hash] :parent ({}) The options for the parent relation. Supports the :relation_name option, which sets the name of the tree's :belongs_to relation, as well as any options normally supported by a :belongs_to relation. @option options [Hash] :children ({}) The options for the children relation. Supports the :relation_name options, which sets the name of the tree's :has_many relation, as well as any options normally supported by a :has_many relation. @option options [Boolean] :cache_ancestry (false) Stores the chain of ancestors in an :ancestor_ids array field. Adds the #ancestors and #descendents scopes. Warning: Using this option will make many write operations much, much slower and more resource-intensive. Do not use this option outside of read-heavy applications with very specific requirements, e.g. a directory structure where you must access all parent directories on each page view. @see Mongoid::SleepingKingStudios::HasTree::CacheAncestry::ClassMethods#cache_ancestry @raise [ Mongoid::Errors::InvalidOptions ] If the options are invalid.
@since 0.4.0
# File lib/mongoid/sleeping_king_studios/has_tree.rb, line 185 def has_tree **options concern = Mongoid::SleepingKingStudios::HasTree concern.apply self, options end