Included Modules

Class/Module Index [+]

Quicksearch

Mongoid::Relations::Referenced::In

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.

Public Class Methods

new(base, target, metadata) click to toggle source

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

Public Instance Methods

nullify() click to toggle source

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
substitute(replacement) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.