Skip to content
Advertisement

Eager loading via QueryBuilder leftJoin

When I wrote:

$query = $this->employeeRepository->createQueryBuilder('e')
    ->leftJoin('e.department', 'd')
;
return $query->getQuery()->getResult();

I expected to get the related eagerly but got Proxy instead. isInitialized false Doctrine proxy

Is there a way to force Doctrine to that relation eagerly without modifying the annotations ?

Advertisement

Answer

You need to select the value too, like:

$query = $this->employeeRepository->createQueryBuilder('e')
    ->select("e", "d")
    ->leftJoin('e.department', 'd')
;
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement