Sha256: 75b7a0698bcb85521f3f9ed6266bad186c6c18cd195cceb6bb51fc777a7505a8
Contents?: true
Size: 1.3 KB
Versions: 19
Compression:
Stored size: 1.3 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 << Mongoid::Factory.from_db(metadata.klass, attrs) else docs << Mongoid::Factory.build(metadata.klass, attrs) end end sort_documents!(docs, metadata) if metadata.order end end end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems