Class: Mongoid::Association::EagerLoad::OtherDatabaseTargets Private

Inherits:
PolymorphicTargets show all
Defined in:
lib/mongoid/association/eager_load/polymorphic_targets.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Targets kept in another database (or cluster), which a $lookup cannot reach. Each type is read directly through its own model, which connects with that model's client.

For { 'Scanner' => [ id2 ] } it runs, on the Scanner model's own client:

scanners.find('_id' => { '$in' => [ id2 ] })

Instance Method Summary collapse

Methods inherited from PolymorphicTargets

for, #initialize

Constructor Details

This class inherits a constructor from Mongoid::Association::EagerLoad::PolymorphicTargets

Instance Method Details

#fetchHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The targets, as { type => { primary_key => document } }.

Returns:

  • (Hash)

    The targets, as { type => { primary_key => document } }.



141
142
143
144
145
146
147
# File 'lib/mongoid/association/eager_load/polymorphic_targets.rb', line 141

def fetch
  @keys_by_type.to_h do |type, keys|
    model = model_for(type)
    documents = model.collection.find(primary_key => { '$in' => keys.uniq })
    [ type, indexed(documents, model) ]
  end
end