fix: [component:CRUD] Fix edit where query parameters where not passed correctly

It fixes meta-fields duplication while saving
pull/93/head
Sami Mokaddem 2022-02-25 08:19:01 +01:00
parent b30dff219b
commit a9570426db
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 12 additions and 6 deletions

View File

@ -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']);
}