From a9570426db57e2775d81b19a49941135f53d60a3 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 25 Feb 2022 08:19:01 +0100 Subject: [PATCH] fix: [component:CRUD] Fix edit where query parameters where not passed correctly It fixes meta-fields duplication while saving --- src/Controller/Component/CRUDComponent.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index 5fcb485..add9d9d 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -454,18 +454,24 @@ class CRUDComponent extends Component $params['contain'][] = 'Tags'; $this->setAllTags(); } - $queryParam = isset($params['get']) ? $params['get'] : $params; + $params = isset($params['get']) ? $params['get'] : $params; if ($this->metaFieldsSupported()) { - if (empty( $queryParam['contain'])) { - $queryParam['contain'] = []; + if (empty($params['contain'])) { + $params['contain'] = []; } - if (is_array( $queryParam['contain'])) { - $queryParam['contain'][] = 'MetaFields'; + if (is_array($params['contain'])) { + $params['contain'][] = 'MetaFields'; } else { - $queryParam['contain'] = [ $queryParam['contain'], 'MetaFields']; + $params['contain'] = [$params['contain'], 'MetaFields']; } } $query = $this->Table->find()->where(['id' => $id]); + if (!empty($params['get'])) { + $query->select($params['get']); + } + if (!empty($params['contain'])) { + $query->contain($params['contain']); + } if (!empty($params['conditions'])) { $query->where($params['conditions']); }