lib/mongoid/association/eager_loadable.rb
# Load the associations for the given documents. This will be done
# recursively to load the associations of the given documents'
# subdocuments.
#
# @param [ Array<Association> ] associations The associations to load.
# @param [ Array<Document> ] document The documents.
Load the associations for the given documents. This will be done
recursively to load the associations of the given documents'
subdocuments.
Load the associations for the given documents . This will be done recursively to load the associations of the given documents ' subdocuments .
def preload(associations, docs)
        assoc_map = associations.group_by(&:inverse_class_name)
        docs_map = {}
        queue = [ klass.to_s ]
        while klass = queue.shift
          if as = assoc_map.delete(klass)
            as.each do |assoc|
              queue << assoc.class_name
              ds = docs
              if assoc.parent_inclusions.length > 0
                ds = assoc.parent_inclusions.map{ |p| docs_map[p].to_a }.flatten
              end
              res = assoc.relation.eager_loader([assoc], ds).run
              docs_map[assoc.name] ||= [].to_set
              docs_map[assoc.name].merge(res)
            end
          end
        end
      end
def preload ( associations , docs ) assoc_map = associations . group_by ( & :inverse_class_name ) docs_map = { } queue = [ klass . to_s ] while klass = queue . shift if as = assoc_map . delete ( klass ) as . each do | assoc | queue << assoc . class_name ds = docs if assoc . parent_inclusions . length > 0 ds = assoc . parent_inclusions . map { | p | docs_map [ p ] . to_a } . flatten end res = assoc . relation . eager_loader ( [ assoc ] , ds ) . run docs_map [ assoc . name ] ||= [ ] . to_set docs_map [ assoc . name ] . merge ( res ) end end end end
Load the associations for the given documents.
Load the associations for the given documents .
# If this class is nested in the inclusion tree, only load documents # for the association above it. If there is no parent association, # we will include documents from the documents passed to this method.
associations
<not_specific>
docs
<not_specific>
<not_specific>
document The documents.
document The documents .