Methods

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 Instance Methods

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 39
def substitute(replacement)
  tap do |proxy|
    proxy.unbind_one
    return nil unless replacement
    proxy.target = replacement
    proxy.bind_one
  end
end

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 20
def initialize(base, target, metadata)
  init(base, target, metadata) do
    characterize_one(target)
    bind_one
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.