chg: [CRUD] component - only try to unlink MetaFields if it's actually loaded

cli-modification-summary
iglocska 2022-11-09 13:58:02 +01:00
parent 7675e27e90
commit 10ce8beb30
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 8 additions and 1 deletions

View File

@ -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);