EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
3.99k stars 1.01k forks source link

Selecting a COUNT() from related entity provides valid query, but null result in the field #6287

Closed FractalizeR closed 1 week ago

FractalizeR commented 2 weeks ago

I'm trying to show a count() of a related entity on a list page

.....
   TextField::new('bankAgendaCount', 'count')->hideOnForm()->setDisabled(),
......

    public function createIndexQueryBuilder(
        SearchDto $searchDto,
        EntityDto $entityDto,
        FieldCollection $fields,
        FilterCollection $filters
    ): QueryBuilder {
        $queryBuilder = parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters);
        $queryBuilder->addSelect(
            '(SELECT COUNT(ba) FROM App\\Entity\\BankAgenda ba WHERE ba MEMBER OF entity.bankAgendas) AS HIDDEN bankAgendaCount'
        );

        return $queryBuilder;
    }

It works, query is constructed correctly (it can be seen in Symfony debug toolbar, if I execute it - it provides correct results), but the resulting field is empty if you try to inspect it (list page shows 'null' as this page value:

image

Do I do something incorrectly? I tried to mark field as vitual, rename it to snake_caase variant in a query. No luck.

FractalizeR commented 1 week ago

Closing as a duplicate of https://github.com/EasyCorp/EasyAdminBundle/issues/5692