Sha256: 09c6e33d95d004ca343614d24aa241adeba2f473cd094b1f60b60dc42edf6dec
Contents?: true
Size: 1.21 KB
Versions: 36
Compression:
Stored size: 1.21 KB
Contents
# encoding: utf-8 module Mongoid module Relations module Builders module Referenced class ManyToMany < Builder # This builder either takes a hash and queries for the # object or an array of documents, where it will just return them. # # @example Build the documents. # Builder.new(meta, attrs).build # # @param [ String ] type The type of document to query for. # # @return [ Array<Document> ] The documents. def build(type = nil) return object.try(:dup) unless query? ids = object || [] crit = metadata.criteria(ids, base.class) IdentityMap.get(crit.klass, ids) || crit end # Do we need to perform a database query? It will be so if the object we # have is not a document. # # @example Should we query the database? # builder.query? # # @return [ true, false ] Whether a database query should happen. # # @since 2.0.0.rc.1 def query? object.nil? || !object.first.is_a?(Mongoid::Document) end end end end end end
Version data entries
36 entries across 36 versions & 5 rubygems