FieryCat
FieryCat

Reputation: 1889

Doctrine select with null

Is there a possibility to execute something like:

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

And avoid:

Doctrine\ORM\Query\QueryException: ... got 'NULL'

Upvotes: 7

Views: 2469

Answers (2)

user15424515
user15424515

Reputation: 36

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

Upvotes: 2

Goran Jurić
Goran Jurić

Reputation: 1839

What you want could be achieved by using the DBAL connection directly and issuing a normal SQL query.

The query builder is used to generate a DQL (Domain Query Language) and this null field is not part of your domain.

Or just select it without the NULL field and run through the results and add it manually.

Upvotes: 0

Related Questions