This class defines the behaviour necessary to handle relations that are embedded within another relation, either as a single document or multiple documents.
Instantiate a new embedded_in relation.
@example Create the new relation.
Embedded::In.new(name, person, metadata)
@param [ Document ] base The document the relation hangs off of. @param [ Document ] target The target (parent) of the relation. @param [ Metadata ] metadata The relation metadata.
@return [ In ] The proxy.
# File lib/mongoid/relations/embedded/in.rb, line 20 def initialize(base, target, metadata) init(base, target, metadata) do characterize_one(target) bind_one end end
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/in.rb, line 38 def substitute(replacement) unbind_one unless replacement base.delete if persistable? return nil end base.new_record = true self.target = replacement bind_one self end