From 10ce8beb30977abbd59635ded0fbb8e0070b0a5e Mon Sep 17 00:00:00 2001 From: iglocska Date: Wed, 9 Nov 2022 13:58:02 +0100 Subject: [PATCH] chg: [CRUD] component - only try to unlink MetaFields if it's actually loaded --- src/Controller/Component/CRUDComponent.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component/CRUDComponent.php b/src/Controller/Component/CRUDComponent.php index ba3ba59..5216086 100644 --- a/src/Controller/Component/CRUDComponent.php +++ b/src/Controller/Component/CRUDComponent.php @@ -554,7 +554,14 @@ class CRUDComponent extends Component $savedData = $this->Table->save($data); if ($savedData !== false) { if ($this->metaFieldsSupported() && !empty($metaFieldsToDelete)) { - $this->Table->MetaFields->unlink($savedData, $metaFieldsToDelete); + foreach ($metaFieldsToDelete as $k => $v) { + if ($v === null) { + unset($metaFieldsToDelete[$k]); + } + } + if (!empty($metaFieldsToDelete)) { + $this->Table->MetaFields->unlink($savedData, $metaFieldsToDelete); + } } if (isset($params['afterSave'])) { $params['afterSave']($data);