Module Mongoid::Relations::Accessors
In: lib/mongoid/relations/accessors.rb

This module contains all the behaviour related to accessing relations through the getters and setters, and how to delegate to builders to create new ones.

Methods

Public Instance methods

Builds the related document and creates the relation unless the document is nil, then sets the relation on this document.

@example Build the relation.

  person.build(:addresses, { :id => 1 }, metadata)

@param [ String, Symbol ] name The name of the relation. @param [ Hash, BSON::ObjectId ] object The id or attributes to use. @param [ Metadata ] metadata The relation‘s metadata. @param [ true, false ] building If we are in a build operation.

@return [ Proxy ] The relation.

@since 2.0.0.rc.1

Create a relation from an object and metadata.

@example Create the relation.

  person.create_relation(document, metadata)

@param [ Document, Array<Document ] object The relation target. @param [ Metadata ] metadata The relation metadata.

@return [ Proxy ] The relation.

@since 2.0.0.rc.1

Determines if the relation exists or not.

@example Does the relation exist?

  person.relation_exists?(:people)

@param [ String ] name The name of the relation to check.

@return [ true, false ] True if set and not nil, false if not.

@since 2.0.0.rc.1

Set the supplied relation to an instance variable on the class with the provided name. Used as a helper just for code cleanliness.

@example Set the proxy on the document.

  person.set(:addresses, addresses)

@param [ String, Symbol ] name The name of the relation. @param [ Proxy ] relation The relation to set.

@return [ Proxy ] The relation.

@since 2.0.0.rc.1

[Validate]