From 11e3858042ed893e404a4a755c928964dd675ec2 Mon Sep 17 00:00:00 2001 From: Luciano Righetti Date: Thu, 10 Aug 2023 16:22:30 +0200 Subject: [PATCH] fix: do not override json column if not present --- src/Model/Behavior/JsonFieldsBehavior.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Model/Behavior/JsonFieldsBehavior.php b/src/Model/Behavior/JsonFieldsBehavior.php index 611a56ef8..2eb2f3656 100644 --- a/src/Model/Behavior/JsonFieldsBehavior.php +++ b/src/Model/Behavior/JsonFieldsBehavior.php @@ -2,13 +2,13 @@ namespace App\Model\Behavior; -use Cake\ORM\Behavior; -use Cake\Event\EventInterface; -use Cake\Datasource\EntityInterface; +use App\Lib\Tools\JsonTool; use ArrayObject; use Cake\Collection\CollectionInterface; +use Cake\Datasource\EntityInterface; +use Cake\Event\EventInterface; +use Cake\ORM\Behavior; use Cake\ORM\Query; -use App\Lib\Tools\JsonTool; class JsonFieldsBehavior extends Behavior { @@ -21,6 +21,9 @@ class JsonFieldsBehavior extends Behavior $config = $this->getConfig(); foreach ($config['fields'] as $field) { + if (!$entity->has($field)) { + continue; + } $value = $entity->get($field); $entity->set($field, JsonTool::encode($value)); }