Doctrine 2: Writing the Right Subheading

I am trying to return the $qb totals before applying the START and LIMIT property to the $qb query. My $qb and $totalQb work just fine themselves, but when I try to use $qb as a subselect, I get an error message:

 $qb = $this->entityManager->createQueryBuilder() ->select('w, se') ->from('Dashboard\Entity\Section', 'se') ->innerJoin('se.word', 'w') ->innerJoin('se.location', 'l'); $qb->add('where', $qb->expr()->andx( $qb->expr()->eq('l.ignored', $ignored), $qb->expr()->eq('l.id', $params['l_id']) ), true); 

Everything above this line in itself works great

 $totalQb = $this->entityManager->createQueryBuilder() ->select('COUNT(x.id)') ->from('Dashboard\Entity\Section', 'x'); 

The above $ totalQb works fine. But when I do the following, and try to use $ qb as a subtask of $ totalQb ...

 $dql = $qb->getDql(); $totalQb->add('where', $totalQb->expr()->exists( $dql )); $totalSql = $totalQb->getQuery(); $sql = $totalSql->getSql(); $total = $totalSql->getSingleScalarResult(); 

THIS IS AN ERROR THROWN

It refers to the SubSelect 'exists' statement. But when I run $ dql by itself, it returns the expected results

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

What is the correct way to perform a subselect in my scenario?

UPDATE It was suggested to add $totalSql->getDQL(); . This is the result of this statement:

 SELECT COUNT(x.id) FROM Dashboard\Entity\Section x WHERE EXISTS( SELECT w, se FROM Dashboard\Entity\Section se INNER JOIN se.word w INNER JOIN se.location l AND (l.ignored = 0) AND (l.id = 2) GROUP BY w.id, l.id ) 
+4
source share
1 answer

I managed to fix the above query by changing the internal -> select to pull from only one table.

+1
source

All Articles