As a good practice i'm tring to hydrate an object as small as possible since data is going to be read only (just show the entity in my Twig template). So i've tried HYDRATE_SIMPLEOBJECT
hydratation mode but i'm getting this exception:
Cannot use SimpleObjectHydrator with a ResultSetMapping that contains more than one object result.
How should i interpret this message? By the way, here is the code that throws the exception:
protected function getFindAllQueryBuilder()
{
return $this->createQueryBuilder('p')
->select(array('p', 'parent', 'features', 'users'))
->leftJoin('p.parent', 'parent')
->leftJoin('p.features', 'features')
->leftJoin('p.users', 'users');
}
public function findOneBySlugAsObject($slug)
{
$qb = $this->getFindAllQueryBuilder();
return $qb
->where($qb->expr()->eq('p.slug', ':slug'))
->setParameter('slug', $slug)
->getQuery()->getOneOrNullResult(Query::HYDRATE_SIMPLEOBJECT);
}
SimpleObjectHydrator is for result sets where you don't use any fetch joins in your query, in other words you can't use it if you use more than one alias in your select. SimpleObjectHydrator is faster because doesn't handle these fetch joins.