Mongolid\Model\Relations::referencesOne PHP Метод

referencesOne() защищенный Метод

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.
Результат mixed
    protected function referencesOne(string $entity, string $field)
    {
        $referenced_id = $this->{$field};
        if (is_array($referenced_id) && isset($referenced_id[0])) {
            $referenced_id = $referenced_id[0];
        }
        $entityInstance = Ioc::make($entity);
        if ($entityInstance instanceof Schema) {
            $dataMapper = Ioc::make(DataMapper::class);
            $dataMapper->setSchema($entityInstance);
            return $dataMapper->first(['_id' => $referenced_id], [], true);
        }
        return $entityInstance::first(['_id' => $referenced_id], [], true);
    }