I am facing issue with mysql CASE in where clause of doctrine,
$rides_q1 = $em->getRepository('IRRideBundle:Ride');
$query = $rides_q1->createQueryBuilder('a')
->where('(CASE WHEN a.ephemeral = 1 THEN a.date_beginning < NOW() AND a.date_ending > NOW()ELSE a.ephemeral = 0 END) AND a.active = 1 AND a.status = 5')
->getQuery();
$ridesQuery = $query->execute();
**[Syntax Error] line 0, col 93: Error: Expected Doctrine\ORM\Query\Lexer::T_ELSE, got '<'**
[2/2] QueryException: [Syntax Error] line 0, col 93: Error: Expected Doctrine\ORM\Query\Lexer::T_ELSE, got '<' +
[1/2] QueryException: SELECT a FROM IR\RideBundle\Entity\Ride a WHERE (CASE WHEN ephemeral = 1 THEN date_beginning < NOW() AND date_ending > NOW()ELSE ephemeral = 0 END)
I want to prepare this sql query, its working fine with phpmyadmin
SELECT * FROM ride WHERE (CASE WHEN ephemeral = 1 THEN date_beginning < NOW() AND date_ending > NOW()ELSE ephemeral = 0 END) AND active = 1 AND `status_id` = 5 ORDER BY `date_ending` DESC