protected function referencesOne(string $entity, string $field, bool $cacheable = true)
    {
        $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], [], $cacheable);
        }

        return $entityInstance::first(['_id' => $referenced_id], [], $cacheable);
    }
protected function referencesOne(string $entity, string $field, bool $cacheable = true)
    {
        $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], [], $cacheable);
        }

        return $entityInstance::first(['_id' => $referenced_id], [], $cacheable);
    }
protected function referencesOne ( string $ entity , string $ field , bool $ cacheable = true ) { $ 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 ] , [ ] , $ cacheable ) ; } return $ entityInstance :: first ( [ '_id' => $ referenced_id ] , [ ] , $ cacheable ) ; }
Returns the referenced documents as objects.

@param string $entity    class of the entity or of the schema of the entity
@param string $field     the field where the _id is stored
@param bool   $cacheable retrieves a CacheableCursor instead

@return mixed
Returns the referenced documents as objects .