aarondfrancis / fast-paginate

A fast implementation of offset/limit pagination for Laravel.
MIT License
1.21k stars 56 forks source link

seem like not working with group by #19

Closed wikichua closed 2 years ago

wikichua commented 2 years ago

Hi there.

Honestly. this is a great package which really improved performance in my 1m dataset. Thanks very much.

However i came across this exception on this part. Paginate() so far working good.

Exception: SQLSTATE[42000]: Syntax error or access violation: 1055 'bliss.permissions.id' isn't in GROUP BY
Raw Sql: select count(*) as aggregate from (select `permissions`.`id` from `permissions` group by `group`) as `aggregate_table`
$rows = app(config('demo.Models.Permission'))->query()
            ->select([
                'group',
                \DB::raw('min(`id`) as id'),
            ])->groupBy('group')
            ->filter($this->filters)
            ->sorting($this->sorts)
            ->fastPaginate($this->take);
aarondfrancis commented 2 years ago

Hey @wikichua, thanks for opening this! Indeed, groups won't work because we're relying on the inner query returning a single primary key that we can use in the outer query. Good catch. I've added a check for that so it will fall back to the regular paginator. Thanks!