Class: Mongoid::Association::EagerLoad::PolymorphicTargets Private
- Inherits:
-
Object
- Object
- Mongoid::Association::EagerLoad::PolymorphicTargets
- 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.
The targets of a polymorphic belongs_to, indexed as { type => { primary_key => document } }. Each subclass reaches the types that live in one place (the root's database or elsewhere); .for resolves the whole set, routing each type to the subclass that can reach it.
Direct Known Subclasses
Class Method Summary collapse
-
.for(association, keys_by_type, root_class) ⇒ Hash
private
Resolve every polymorphic target for the foreign keys grouped by type.
Instance Method Summary collapse
-
#fetch ⇒ Hash
private
The targets, as { type => { primary_key => document } }.
-
#initialize(association, keys_by_type) ⇒ PolymorphicTargets
constructor
private
A new instance of PolymorphicTargets.
Constructor Details
#initialize(association, keys_by_type) ⇒ PolymorphicTargets
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 a new instance of PolymorphicTargets.
43 44 45 46 |
# File 'lib/mongoid/association/eager_load/polymorphic_targets.rb', line 43 def initialize(association, keys_by_type) @association = association @keys_by_type = keys_by_type end |
Class Method Details
.for(association, keys_by_type, root_class) ⇒ Hash
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.
Resolve every polymorphic target for the foreign keys grouped by type. The types whose documents share the root's database are fetched together in one $facet; those living elsewhere are read through their own models.
23 24 25 26 27 28 29 30 |
# File 'lib/mongoid/association/eager_load/polymorphic_targets.rb', line 23 def for(association, keys_by_type, root_class) here, elsewhere = keys_by_type.partition do |type, _keys| in_root_database?(association, type, root_class) end same_database = SameDatabaseTargets.new(association, here.to_h, root_class) other_databases = OtherDatabaseTargets.new(association, elsewhere.to_h) same_database.fetch.merge(other_databases.fetch) end |
Instance Method Details
#fetch ⇒ Hash
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 } }.
49 50 51 |
# File 'lib/mongoid/association/eager_load/polymorphic_targets.rb', line 49 def fetch raise NotImplementedError end |