src/Graviton/SchemaBundle/Constraint/ConstraintUtils.php
private function getSingleEntity($documentClass, $recordId, array $fields = null)
    {
        // only get certain fields! will not be cached in instance
        $queryBuilder = $this->dm->createQueryBuilder($documentClass);
        $queryBuilder->field('id')->equals($recordId);
        if (is_array($fields)) {
            $queryBuilder->select($fields);
        }
        $query = $queryBuilder->getQuery();
        $query->setRefresh(true);
        $records = array_values($query->execute()->toArray());

        if (is_array($records) && !empty($records)) {
            return json_decode($this->restUtils->serializeContent($records[0]));
        }

        return null;
    }
private function getSingleEntity($documentClass, $recordId, array $fields = null)
    {
        // only get certain fields! will not be cached in instance
        $queryBuilder = $this->dm->createQueryBuilder($documentClass);
        $queryBuilder->field('id')->equals($recordId);
        if (is_array($fields)) {
            $queryBuilder->select($fields);
        }
        $query = $queryBuilder->getQuery();
        $query->setRefresh(true);
        $records = array_values($query->execute()->toArray());

        if (is_array($records) && !empty($records)) {
            return json_decode($this->restUtils->serializeContent($records[0]));
        }

        return null;
    }
private function getSingleEntity ( $ documentClass , $ recordId , array $ fields = null ) { // only get certain fields! will not be cached in instance $ queryBuilder = $ this -> dm -> createQueryBuilder ( $ documentClass ) ; $ queryBuilder -> field ( 'id' ) -> equals ( $ recordId ) ; if ( is_array ( $ fields ) ) { $ queryBuilder -> select ( $ fields ) ; } $ query = $ queryBuilder -> getQuery ( ) ; $ query -> setRefresh ( true ) ; $ records = array_values ( $ query -> execute ( ) -> toArray ( ) ) ; if ( is_array ( $ records ) && ! empty ( $ records ) ) { return json_decode ( $ this -> restUtils -> serializeContent ( $ records [ 0 ] ) ) ; } return null ; }
returns an already serialized entity depending on fields, making sure the
query is fresh

@param string $documentClass document class
@param string $recordId      record id
@param array  $fields        if you only need certain fields, you can specify them here

@throws \Exception

@return object|null entity
returns an already serialized entity depending on fields making sure the query is fresh