I have a schema which includes a one to many relationship between a Page and Report. Reports has a date field and I want to fetch a count of Reports per Page within a given time frame along with all the Page data and filtered Reports.
$this->createQueryBuilder('p')
->leftJoin('p.reports', 'page_reports')
->addSelect('page_reports')
->where('page_reports.datetime > :since')
->setParameter('since', new DateTime('-15 days'))
->getQuery()
->execute();
The above returns Page entities where the Reports collection is filtered by the date but I do not know how to additionally return a count of Reports per page while also maintaining the filtered Reports
. Am I going about this the right way or should I be just querying for the Pages and then applying a filter to the Reports collection.
James Hall is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.