fix: do not override json column if not present

pull/9246/head
Luciano Righetti 2023-08-10 16:22:30 +02:00
parent d7183d69a0
commit 11e3858042
1 changed files with 7 additions and 4 deletions

View File

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