Skip to content

Instantly share code, notes, and snippets.

@technoknol
Last active May 18, 2021 18:10
Show Gist options
  • Save technoknol/141d01822e495d5e9111fd43177331cf to your computer and use it in GitHub Desktop.
Save technoknol/141d01822e495d5e9111fd43177331cf to your computer and use it in GitHub Desktop.
Doctrine SubQuery using getDQL
<?php
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder2 = $this->entityManager->createQueryBuilder();
$subQuery = $queryBuilder2->select('COUNT(fr.status)')
->from(FeedbackRequest::class, 'fr')
->where('fr.giverId = iu.userId')
->groupBy('fr.status')
$Query = $queryBuilder->select('iu')
->addSelect("(".$subQuery->getDQL().") statusCount")
->from(InstitutionUser::class, 'iu')
->setMaxResults(10)
->getQuery()
->getResult()
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment