Method: Mongoid::Relations::Accessors#create_relation

Defined in:
lib/mongoid/relations/accessors.rb

#create_relation(object, metadata) ⇒ Proxy

Create a relation from an object and metadata.

Examples:

Create the relation.

person.create_relation(document, )

Parameters:

  • Document, (Document, Array<Document ] object The relation target.)

    Array<Document ] object The relation target.

  • metadata (Metadata)

    The relation metadata.

Returns:

  • (Proxy)

    The relation.

Since:

  • 2.0.0.rc.1



41
42
43
44
45
# File 'lib/mongoid/relations/accessors.rb', line 41

def create_relation(object, )
  type = @attributes[.inverse_type]
  target = .builder(self, object).build(type)
  target ? .relation.new(self, target, ) : nil
end