Class: Mongoid::Relations::Eager::HasOne

Inherits:
Base
  • Object
show all
Defined in:
build/mongoid-6.1/lib/mongoid/relations/eager/has_one.rb

Instance Method Summary collapse

Methods inherited from Base

#each_loaded_document, #grouped_docs, #initialize, #keys_from_docs, #run, #set_on_parent, #shift_metadata

Constructor Details

This class inherits a constructor from Mongoid::Relations::Eager::Base

Instance Method Details

#group_by_keyObject



19
20
21
# File 'build/mongoid-6.1/lib/mongoid/relations/eager/has_one.rb', line 19

def group_by_key
  @metadata.primary_key
end

#keyObject



23
24
25
# File 'build/mongoid-6.1/lib/mongoid/relations/eager/has_one.rb', line 23

def key
  @metadata.foreign_key
end

#preloadObject



8
9
10
11
12
13
14
15
16
17
# File 'build/mongoid-6.1/lib/mongoid/relations/eager/has_one.rb', line 8

def preload
  @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