Mongolid\Model\DocumentEmbedder::unembed PHP Method

unembed() public method

Removes the given $entity from $field of $parent. This method will consider the _id of the $entity in order to remove it.
public unembed ( mixed $parent, string $field, mixed &$entity ) : boolean
$parent mixed The object where the $entity will be removed.
$field string Name of the field of the object where the document is.
$entity mixed Entity that will be removed from $parent.
return boolean Success
    public function unembed($parent, string $field, &$entity) : bool
    {
        $fieldValue = (array) $parent->{$field};
        $id = $this->getId($entity);
        foreach ($fieldValue as $key => $document) {
            if ($id == $this->getId($document)) {
                unset($fieldValue[$key]);
            }
        }
        $parent->{$field} = array_values($fieldValue);
        return true;
    }