Method: SimpleNestedSet::ClassMethods#trees

Defined in:
lib/simple_nested_set/class_methods.rb

#trees(scope = nil) ⇒ Object

Returns all roots recursively pre-populated with their children associations



14
15
16
17
18
19
# File 'lib/simple_nested_set/class_methods.rb', line 14

def trees(scope = nil)
  nodes = nested_set_class.scope(scope)
  nodes.select(&:root?).each do |root|
    root.nested_set.populate_associations(nodes.select { |node| node.descendent_of?(root) })
  end
end