# encoding: utf-8 module Mongoid # :nodoc: module Relations #:nodoc: # 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. module Accessors extend ActiveSupport::Concern # 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 def build(name, object, metadata) relation = create_relation(object, metadata) set_relation(name, relation) end # Create a relation from an object and metadata. # # @example Create the relation. # person.create_relation(document, metadata) # # @param [ Document, Array