This class defines the behaviour needed for embedded one to one relations.
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
# File lib/mongoid/relations/embedded/one.rb, line 36 def substitute(replacement) tap do |proxy| if _assigning? base.atomic_unsets.push(proxy.atomic_path) else proxy.delete if persistable? end proxy.unbind_one return nil unless replacement proxy.target = replacement proxy.bind_one end end
Instantiate a new embeds_one relation.
@example Create the new proxy.
One.new(person, name, metadata)
@param [ Document ] base The document this relation hangs off of. @param [ Document ] target The child document in the relation. @param [ Metadata ] metadata The relation’s metadata
# File lib/mongoid/relations/embedded/one.rb, line 17 def initialize(base, target, metadata) init(base, target, metadata) do characterize_one(target) bind_one target.save if persistable? end end
Generated with the Darkfish Rdoc Generator 2.