PHP Trait Mongolid\Model\Relations

Datei anzeigen Open project: leroy-merlin-br/mongolid

Public Methods

Method Description
attach ( string $field, mixed &$obj ) : void Attach document _id reference to an attribute. It will also generate an _id for the document if it's not present.
detach ( string $field, mixed &$obj ) : void Removes a document _id reference from an attribute. It will remove the _id of the given $obj from inside the given $field.
embed ( string $field, mixed &$obj ) : void Embed a new document to an attribute. It will also generate an _id for the document if it's not present.
unembed ( string $field, mixed &$obj ) : void Removes an embedded document from the given field. It does that by using the _id of the given $obj.

Protected Methods

Method Description
embedsMany ( string $entity, string $field ) : EmbeddedCursor Return array of embedded documents as objects.
embedsOne ( string $entity, string $field ) : Model | null Return a embedded documents as object.
referencesMany ( string $entity, string $field ) : array Returns the cursor for the referenced documents as objects.
referencesOne ( string $entity, string $field ) : mixed Returns the referenced documents as objects.

Method Details

attach() public method

Attach document _id reference to an attribute. It will also generate an _id for the document if it's not present.
public attach ( string $field, mixed &$obj ) : void
$field string Name of the field where the reference will be stored.
$obj mixed Document, model instance or _id to be referenced.
return void

detach() public method

Removes a document _id reference from an attribute. It will remove the _id of the given $obj from inside the given $field.
public detach ( string $field, mixed &$obj ) : void
$field string Field where the reference is stored.
$obj mixed Document, model instance or _id that have been referenced by $field.
return void

embed() public method

Embed a new document to an attribute. It will also generate an _id for the document if it's not present.
public embed ( string $field, mixed &$obj ) : void
$field string Field to where the $obj will be embedded.
$obj mixed Document or model instance.
return void

embedsMany() protected method

Return array of embedded documents as objects.
protected embedsMany ( string $entity, string $field ) : EmbeddedCursor
$entity string Class of the entity or of the schema of the entity.
$field string Field where the embedded documents are stored.
return Mongolid\Cursor\EmbeddedCursor Array with the embedded documents

embedsOne() protected method

Return a embedded documents as object.
protected embedsOne ( string $entity, string $field ) : Model | null
$entity string Class of the entity or of the schema of the entity.
$field string Field where the embedded document is stored.
return Model | null

referencesMany() protected method

Returns the cursor for the referenced documents as objects.
protected referencesMany ( string $entity, string $field ) : array
$entity string Class of the entity or of the schema of the entity.
$field string The field where the _ids are stored.
return array

referencesOne() protected method

Returns the referenced documents as objects.
protected referencesOne ( string $entity, string $field ) : mixed
$entity string Class of the entity or of the schema of the entity.
$field string The field where the _id is stored.
return mixed

unembed() public method

Removes an embedded document from the given field. It does that by using the _id of the given $obj.
public unembed ( string $field, mixed &$obj ) : void
$field string Name of the field where the $obj is embeded.
$obj mixed Document, model instance or _id.
return void