Using a 'case when' in a Doctrine select statement

I just had the same problem and, at first glance, appear to have a workaround. I believe you can 'fool' the Doctrine Select parser into treating it as a sub-query by wrapping it in parenthesis.

Give this a try:

$resultset = Doctrine_Query::create()
->select("t.code, t.description, (case when t.id_outcome = 1 then 1 else 0 end) as in_progress")
->from('LuOutcome t')
->orderBy('t.rank')
->fetchArray();

Case statements do appear to have been added to doctrine at some point: https://github.com/doctrine/orm-documentation/commit/189c729f15d2fafecf92662cad9553c2ec3dccd7#diff-0


The BNF grammar for the Doctrine Query Language doesn't seem to contain anything related to a CASE construct.

Tags:

Sql

Php

Doctrine