Class: Mongoid::Relations::Builders::Embedded::Many
- Inherits:
-
Mongoid::Relations::Builder
- Object
- Mongoid::Relations::Builder
- Mongoid::Relations::Builders::Embedded::Many
- Includes:
- Embedded::Sort
- Defined in:
- lib/mongoid/relations/builders/embedded/many.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from Mongoid::Relations::Builder
Instance Method Summary collapse
-
#build(type = nil) ⇒ Array<Document ] The documents.
Builds the document out of the attributes using the provided metadata on the relation.
Methods included from Embedded::Sort
Methods inherited from Mongoid::Relations::Builder
Constructor Details
This class inherits a constructor from Mongoid::Relations::Builder
Instance Method Details
#build(type = nil) ⇒ Array<Document ] The documents.
Builds the document out of the attributes using the provided metadata on the relation. Instantiates through the factory in order to make sure subclasses and allocation are used if fitting. This case will return many documents.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/relations/builders/embedded/many.rb', line 22 def build(type = nil) return [] if object.blank? return object if object.first.is_a?(Document) [].tap do |docs| object.each do |attrs| if _loading? docs << Factory.from_db(klass, attrs) else docs << Factory.build(klass, attrs) end end sort_documents!(docs, ) if .order end end |