From cfea15ff0355a02e12703ce79cacec1e6e48af16 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Mon, 18 Jan 2021 16:13:10 +0100 Subject: [PATCH] fix: [component:CRUD] Fixed FULL_GROUP_BY issue and simplified contextual filtering --- src/Controller/Component/CRUDComponent.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index c67df3f..ddaf00c 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -519,15 +519,14 @@ class CRUDComponent extends Component $fieldToExtract = sprintf('%s.%s', Inflector::singularize(strtolower($model)), $subField); } $query = $this->Table->find()->contain($model); - return $query->all()->extract($fieldToExtract)->reduce(function ($output, $value) { - if (!in_array($value, $output)) { - $output[] = $value; - } - return $output; - }, []); } else { - return $this->Table->find()->distinct([$field])->all()->extract($field)->toList(); + $fieldToExtract = $field; + $query = $this->Table->find(); } + return $query->select([$field]) + ->distinct() + ->extract($fieldToExtract) + ->toList(); } private function renderViewInVariable($templateRelativeName, $data)