Class: ActsAsRecursiveTree::Preloaders::Descendants

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_recursive_tree/preloaders/descendants.rb

Overview

Preloads all descendants records for a given node and sets the parent and child associations on each record based on the preloaded data. After this, calling #parent or #children will not trigger a database query.

Instance Method Summary collapse

Constructor Details

#initialize(node, includes: nil) ⇒ Descendants

Returns a new instance of Descendants.



10
11
12
13
14
# File 'lib/acts_as_recursive_tree/preloaders/descendants.rb', line 10

def initialize(node, includes: nil)
  @node       = node
  @parent_key = node._recursive_tree_config.parent_key
  @includes   = includes
end

Instance Method Details

#preload!Object



16
17
18
# File 'lib/acts_as_recursive_tree/preloaders/descendants.rb', line 16

def preload!
  apply_records(@node)
end