Symfony2 + Doctrine : select query with conditional statment

1.9k Views Asked by At

I would like to do something like :

return $qb
        ->select("f, g")
        ->addSelect(" (CASE WHEN (f.type = 'p') THEN 'panel' ELSE 'glass' END) as 'typeLable' ")
        ->from("Win4uAdminBundle:Filling", "f")
        ->join("f.gammes", "g")
        ->andWhere("f.isActive = :active")
        ->andWhere("g.id = :gamme")
        ->setParameter("active", 1)
        ->setParameter("gamme", $gammeId)

But doesn't work. error is :

[Syntax Error] line 0, col 74: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got 'typeLable'

The goal is select the type and translate it in the query.

Thanks!

1

There are 1 best solutions below

4
On BEST ANSWER

It is just a typo, typeLable should be without quotes:

->addSelect(" (CASE WHEN f.type = 'p' THEN 'panel' ELSE 'glass' END) as typeLable ")