Вот как я это исправил:
Переопределение renderTemplate в пользовательском AdminController:
protected function renderTemplate($actionName, $templatePath, array $parameters = array())
{
if ($actionName === 'list' && $this->entity['class'] === ClassA::class) {
//piggyback on virtual property 'count'
$parameters['fields']['count']['servicecounts'] = $this->MyEntityRepository->getCounts();
}
return $this->render($templatePath, $parameters);
}
easy_admin config:
list:
fields:
- { property: 'count', template: 'count.html.twig' }
count.html.twig:
{{ field_options.servicecounts[item.id] }}
Функция getCounts:
public function getCounts()
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->select('s.id, count(ce.recordId)')
->from(ClassA::class, 's')
->leftJoin(ClassB::class, 'ce', Join::WITH, 's.id = ce.service')
->groupBy('s.id')
;
$results = [];
foreach ($qb->getQuery()->execute() as $row) {
$results[$row['id']] = $row[1];
}
return $results;
}