Sha256: 9682bfff7eb7808e893a9ebf41e65192e41ccfb90b9a2c7aad36b4c57c7c8e80

Contents?: true

Size: 775 Bytes

Versions: 10

Compression:

Stored size: 775 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.match(criteria) || criteria.first
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongoid-2.1.9 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.8 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.7 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.6 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.5 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.4 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.3 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.2 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.1 lib/mongoid/relations/builders/referenced/one.rb
mongoid-2.1.0 lib/mongoid/relations/builders/referenced/one.rb