Answer the question
In order to leave comments, you need to log in
Doctrine, how to count the number of records with join?
There is a request to get data (request shortened for convenience):
$qb = $this->entityManager->createQueryBuilder()
->select(['record', 'type'])
->from(Record::class, 'record')
->leftJoin('record.type', 'type');
$criteria = Criteria::create();
$criteria->andWhere(Criteria::expr()->eq('type.alias', 'news'));
$qb->addCriteria($criteria);
$query = $qb->getQuery();
$query->getScalarResult();
Answer the question
In order to leave comments, you need to log in
Option 1. Run a separate query SELECT COUNT(*) ...
, i.e. $qb->count()
Option 2 (a crutch for MySQL only). https://dev.mysql.com/doc/refman/5.7/en/informatio...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question