SonataDoctrineORMAdminBundle icon indicating copy to clipboard operation
SonataDoctrineORMAdminBundle copied to clipboard

Paginator calculates pages and total entity elements wrong with CallbackFilter

Open haivala opened this issue 9 months ago • 2 comments

I'll add these later if needed

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
# Put the result here.

Symfony packages

show

$ composer show --latest 'symfony/*'
# Put the result here.

PHP version

$ php -v
# Put the result here.

Subject

Title

Minimal repository with the bug

Steps to reproduce

            ->add('display_only_unique_members', CallbackFilter::class, [
                'callback' => static function (ProxyQueryInterface $query, string $alias, string $field, FilterData $data): bool {
                    if (!$data->hasValue()) {
                        return false;
                    }

                    assert($query instanceof QueryBuilder);
                    $query
                        ->groupBy('o.member')
                    ;

                    return true;
                },
                'field_type' => CheckboxType::class,
            ])

Using this filter gives wrong results in paginator. Too many pages and too many total results.

Expected results

Results and pages should be calculated right

Actual results

The filter works and the actual data in the table is how it should be but the paginator does not take the query change into account

haivala avatar Feb 19 '25 09:02 haivala

First this is an issue for https://github.com/sonata-project/SonataDoctrineORMAdminBundle since the Callback filter is coming from it.

Secondly, the CallbackFilter/Paginator was never meant to handle groupBy, just adding conditions.

If you want to try to support this, I would recommend to look at https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/4.x/src/Util/SmartPaginatorFactory.php

But I'm pretty sure the paginator won't work well with groupBy.

VincentLanglet avatar Feb 19 '25 10:02 VincentLanglet

Sorry for the wrong repo!

If that does not work well with the Paginator I'm wondering that is there another way to do this than use groupBy? Basically I'm trying to find entries that are unique by relation.

haivala avatar Feb 20 '25 16:02 haivala

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Sep 13 '25 13:09 github-actions[bot]