Sha256: f801834c460cc1224a3781da2b8edf17511c777bbfd9cecf10cef36b2e36695f
Contents?: true
Size: 936 Bytes
Versions: 3
Compression:
Stored size: 936 Bytes
Contents
# encoding: utf-8 module Mongoid # :nodoc: module Relations #:nodoc: module Builders #:nodoc: module Referenced #:nodoc: class One < Builder # This builder either takes an _id or an object and queries for the # inverse side using the id or sets the object. # # @example Build the document. # Builder.new(meta, attrs).build # # @param [ String ] type The type of document to query for. # # @return [ Document ] A single document. def build(type = nil) return object unless query? if object.is_a?(Hash) object.delete(:binding) return Mongoid::Factory.build(metadata.klass, object) end metadata.klass.first( :conditions => { metadata.foreign_key => object } ) end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems