Kreyu/data-table-bundle

Using simple Doctrine queries results in an paginator exception

Kreyu opened this issue · 1 comments

Kreyu commented

Passing a QueryBuilder that returns simple results, such as:

$query = $repository->createQueryBuilder('product')
    ->select('product.name');

results in an exception:

RuntimeException: The Paginator does not support Queries which only yield ScalarResults.

this can be fixed by applying a hint with custom output walker to the query in the data table type builder:

class ProductDataTableType extends AbstractDataTableType
{
    public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
    {
        $builder->getQuery()->setHint(
            \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 
            \Doctrine\ORM\Query\SqlWalker::class,
        );
    }
}

This, however, can be handled automatically, see implementation in Sonata Admin:
https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/4.x/src/Util/SmartPaginatorFactory.php#L66-L68

Fixed in 0.16