Mongolid\Model\Relations::embedsOne PHP Method

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
    protected function embedsOne(string $entity, string $field)
    {
        if (is_subclass_of($entity, Schema::class)) {
            $entity = (new $entity())->entityClass;
        }
        $items = (array) $this->{$field};
        if (false === empty($items) && false === array_key_exists(0, $items)) {
            $items = [$items];
        }
        return Ioc::make(CursorFactory::class)->createEmbeddedCursor($entity, $items)->first();
    }