Sha256: 6de245ba79c3241361306193291440a2376f3f73ac531eda5d23282fb0e1e5ee

Contents?: true

Size: 841 Bytes

Versions: 4

Compression:

Stored size: 841 Bytes

Contents

# encoding: utf-8
module Mongoid # :nodoc:
  module Relations #:nodoc:

    # This is the superclass for one to one relations and defines the common
    # behaviour or those proxies.
    class One < Proxy

      # Substitutes the supplied target documents for the existing document
      # in the relation.
      #
      # @example Substitute the new document.
      #   person.name.substitute(new_name)
      #
      # @param [ Document ] other A document to replace the target.
      #
      # @return [ Document, nil ] The relation or nil.
      #
      # @since 2.0.0.rc.1
      def substitute(new_target, options = {})
        old_target = target
        tap do |relation|
          relation.target = new_target
          new_target ? bind(options) : (unbind(old_target, options) and return nil)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongoid-2.0.0.rc.4 lib/mongoid/relations/one.rb
mongoid-2.0.0.rc.3 lib/mongoid/relations/one.rb
mongoid-2.0.0.rc.2 lib/mongoid/relations/one.rb
mongoid-2.0.0.rc.1 lib/mongoid/relations/one.rb