Doctrine select with null

Tags: , ,



Is there a possibility to execute something like:

$builder = $this->getEntityManager()->createQueryBuilder();
$builder->select(
        'f.id',
        ...
        'NULL AS missing_attribute'
    )
    ->from(..., 'f')
    ...;

And avoid:

DoctrineORMQueryQueryException: ... got 'NULL'

Answer

Workaround from https://github.com/doctrine/orm/issues/1670#issuecomment-591495663: select NULLIF(1,1) AS ... instead of NULL AS ...



Source: stackoverflow