From 58514485f12c422335248245bca67256b2e6df5e Mon Sep 17 00:00:00 2001 From: pxpm Date: Mon, 19 Aug 2024 17:14:34 +0100 Subject: [PATCH] count the group by columns instead of select.* --- src/app/Library/CrudPanel/Traits/Query.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/Library/CrudPanel/Traits/Query.php b/src/app/Library/CrudPanel/Traits/Query.php index a1726fe477..bdfcb8bafa 100644 --- a/src/app/Library/CrudPanel/Traits/Query.php +++ b/src/app/Library/CrudPanel/Traits/Query.php @@ -260,7 +260,8 @@ private function getCountFromQuery(Builder $query) $subQuery = $crudQuery->cloneWithout(['columns', 'orders', 'limit', 'offset']); // select minimum possible columns for the count - $minimumColumns = ($crudQuery->groups || $crudQuery->havings) ? $modelTable.'.*' : $modelTable.'.'.$this->model->getKeyName(); + $columns = $crudQuery->groups ? $crudQuery->groups : $modelTable.'.'.$this->model->getKeyName(); + $minimumColumns = ($crudQuery->groups || $crudQuery->havings) ? $columns : $modelTable.'.'.$this->model->getKeyName(); $subQuery->select($minimumColumns); // in case there are raw expressions we need to add them too. @@ -269,7 +270,6 @@ private function getCountFromQuery(Builder $query) } // re-set the previous query bindings - //dump($crudQuery->getColumns(), get_class($crudQuery), get_class($subQuery)); foreach ($crudQuery->getRawBindings() as $type => $binding) { $subQuery->setBindings($binding, $type); }