Module: Mongoid::Hierarchy

Defined in:
lib/mongoid/core_ext/hierarchy.rb

Instance Method Summary collapse

Instance Method Details

#collect_childrenArray<Document>

Collect all the children of this document.

Examples:

Collect all the children.

document.collect_children

Returns:

  • (Array<Document>)

    The children.

Since:

  • 2.4.0



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mongoid/core_ext/hierarchy.rb', line 11

def collect_children
  children = []
  embedded_relations.each_pair do |name, |
    without_autobuild do
      child = send(name)
      Array.wrap(child).each do |doc|
        children.push(doc)
        children.concat(doc._children) unless .versioned?
      end if child
    end
  end
  children
end