Kreyu / data-table-bundle

Streamlines creation process of the data tables in Symfony applications. NOT PRODUCTION READY.
https://data-table-bundle.swroblewski.pl
MIT License
69 stars 15 forks source link

Using a Doctrine ORM QueryBuilder with multiple, comma separated selects results in an alias resolver error #115

Closed Kreyu closed 1 month ago

Kreyu commented 1 month ago

The Doctrine ORM integration contains an alias resolver. The alias resolver tries to guess an alias of DQL paths given without an explicit alias.

For example, if we create a QueryBuilder of Product entity, and try to sort by the name DQL path, the alias resolver will try to add correct Product alias to the name, e.g. product.name.

If we provide multiple selects inside a single select() / addSelect() call, this completely breaks the alias resolver:

$queryBuilder = $productRepository->createQueryBuilder('product')
    ->select('product.id AS foo, COUNT(commercialGroupSchedules.id) as bar')
;

In above example, the alias resolver is trying to add root alias to the "foo" and "bar", which is incorrect. Temporarily, the workaround is to provide a single select per call:

$queryBuilder = $productRepository->createQueryBuilder('product')
    ->select('product.id AS foo')
    ->addSelect('COUNT(commercialGroupSchedules.id) as bar')
;
Kreyu commented 1 month ago

Fixed in 0.20.1 (https://github.com/Kreyu/data-table-bundle/commit/246608a67d969b2d918c3c4f2e3b3ef238f9d8ad)