This class handles all behaviour for relations that are either one-to-many or one-to-one, where the foreign key is store on this side of the relation and the reference is to document(s) in another collection.
Instantiate a new referenced_in relation.
@example Create the new relation.
Referenced::In.new(game, person, metadata)
@param [ Document ] base The document this relation hangs off of. @param [ Document, Array<Document> ] target The target (parent) of the
relation.
@param [ Metadata ] metadata The relation's metadata.
# File lib/mongoid/relations/referenced/in.rb, line 21 def initialize(base, target, metadata) init(base, target, metadata) do characterize_one(target) bind_one end end
Removes the association between the base document and the target document by deleting the foreign key and the reference, orphaning the target document in the process.
@example Nullify the relation.
person.game.nullify
# File lib/mongoid/relations/referenced/in.rb, line 35 def nullify unbind_one target.save end
Substitutes the supplied target documents for the existing document in the relation.
@example Substitute the relation.
name.substitute(new_name)
@param [ Document, Array<Document> ] new_target The replacement. @param [ true, false ] building Are we in build mode?
@return [ In, nil ] The relation or nil.
@since 2.0.0.rc.1
# File lib/mongoid/relations/referenced/in.rb, line 52 def substitute(replacement) unbind_one return nil unless replacement self.target = replacement bind_one self end