Module: Mongoid::Criterion::EagerLoading

Defined in:
lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eager_loadingsObject

EagerLoading criterion are used when eager loading the associations.

Example:

criteria.includes(:user)

criteria.includes(:user, :post)

Returns: self



13
14
15
# File 'lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb', line 13

def eager_loadings
  @eager_loadings
end

#id_associations_map=(value) ⇒ Object

EagerLoading criterion are used when eager loading the associations.

Example:

criteria.includes(:user)

criteria.includes(:user, :post)

Returns: self



13
14
15
# File 'lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb', line 13

def id_associations_map=(value)
  @id_associations_map = value
end

#id_documents_map=(value) ⇒ Object

EagerLoading criterion are used when eager loading the associations.

Example:

criteria.includes(:user)

criteria.includes(:user, :post)

Returns: self



13
14
15
# File 'lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb', line 13

def id_documents_map=(value)
  @id_documents_map = value
end

Instance Method Details

#includes(*options) ⇒ Object



15
16
17
18
# File 'lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb', line 15

def includes(*options)
  @eager_loadings = options
  self
end

#preload(documents) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb', line 20

def preload(documents)
  return if documents.blank?
  document_class = documents.first.class
  @eager_loadings.each do |eager_loading|
    setup_associations(documents, association_reflection(document_class, eager_loading))
  end
end