Sha256: 45e8b49432e1d2c9190fce3e076054cbbecc23970acbf8bbb35c41d3b17a192d

Contents?: true

Size: 798 Bytes

Versions: 7

Compression:

Stored size: 798 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?
            criteria = metadata.criteria(object)
            IdentityMap.get(criteria.klass, criteria.selector) || criteria.first
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mongoid-2.2.6 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.2.5 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.2.4 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.2.3 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.2.2 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.2.1 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.2.0 lib/mongoid/relations/builders/referenced/one.rb