Sha256: 98e7da25dad25b2cdd6eedcee22d0e5661d08fc79c0e02edb7596f9dd45651f7
Contents?: true
Size: 1.27 KB
Versions: 5
Compression:
Stored size: 1.27 KB
Contents
# encoding: utf-8 require "mongoid/relations/embedded/sort" module Mongoid # :nodoc: module Relations #:nodoc: module Builders #:nodoc: module Embedded #:nodoc: class Many < Builder #:nodoc: include Relations::Embedded::Sort # 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. # # @example Build the documents. # Builder.new(meta, attrs).build # # @param [ String ] type Not used in this context. # # @return [ Array<Document ] The documents. 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, metadata) if metadata.order end end end end end end end
Version data entries
5 entries across 5 versions & 2 rubygems