1

I've got plain sql query that looks like that:

select u.*, 
EXISTS (SELECT * FROM survey_response sr WHERE sr.user_id = u.id AND sr.survey_id = 8) AS hasResponse 
FROM `user` u

and what i want to do, is to build same query using doctrine query builder.

$qb = $this->em->createQueryBuilder();
$qb
    ->from('AppBundle:User', 'u')
    ->select('u');

$qb2 = $this->em->createQueryBuilder();
$qb2
    ->from('AppBundle:Response', 'r')
    ->select('r')
    ->where('r.user = u')
    ->andWhere('r.survey = 8');

$qb->addSelect('EXISTS ('.$qb2->getDQL().') AS hasResponse');

Now when i'm trying to execute query built with query builder, it throws me and "Expected known function, got 'EXISTS'" error. What am i doing wrong?

RlyDontKnow
  • 131
  • 4
  • 13
  • http://stackoverflow.com/questions/10030538/query-with-exists-for-doctrine-symfony2 – jaro1989 Dec 14 '16 at 14:21
  • Is this related? http://stackoverflow.com/questions/16202277/symfony2-doctrine-select-ifnull –  Dec 14 '16 at 14:22

0 Answers0