Methods

Class/Module Index [+]

Quicksearch

Mongoid::Relations::Embedded::In

This class defines the behaviour necessary to handle relations that are embedded within another relation, either as a single document or multiple documents.

Public Instance Methods

substitute(replacement) click to toggle source

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 39
def substitute(replacement)
  tap do |proxy|
    proxy.unbind_one
    unless replacement
      base.delete if persistable?
      return nil
    end
    base.new_record = true
    proxy.target = replacement
    proxy.bind_one
  end
end

Public Class Methods

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

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
    base.save if persistable?
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.