Class: Mongoid::Relations::Eager::BelongsTo
- Inherits:
-
Base
- Object
- Base
- Mongoid::Relations::Eager::BelongsTo
show all
- Defined in:
- lib/mongoid/relations/eager/belongs_to.rb
Instance Method Summary
collapse
Methods inherited from Base
#each_loaded_document, #grouped_docs, #initialize, #keys_from_docs, #run, #set_on_parent, #shift_metadata
Instance Method Details
#group_by_key ⇒ Object
21
22
23
|
# File 'lib/mongoid/relations/eager/belongs_to.rb', line 21
def group_by_key
@metadata.foreign_key
end
|
#key ⇒ Object
25
26
27
|
# File 'lib/mongoid/relations/eager/belongs_to.rb', line 25
def key
@metadata.primary_key
end
|
#preload ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/mongoid/relations/eager/belongs_to.rb', line 8
def preload
raise Errors::EagerLoad.new(@metadata.name) if @metadata.polymorphic?
@docs.each do |d|
set_relation(d, nil)
end
each_loaded_document do |doc|
id = doc.send(key)
set_on_parent(id, doc)
end
end
|