My model is defined as follows:
<?php
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Database\Schema\Table as Schema;
class AppLogsTable extends Table
{
protected function _initializeSchema(Schema $schema) {
$schema->columnType('data', 'json');
return $schema;
}
}
The JSON format is correctly applied when saving into database and when retrieving data. However, if I set $appLog->data = null
and save it through $this->appLogs->save($appLog)
it would save a string null
into the database rather than a real NULL value. The colum data
in the app_logs
table is set to accept nulls.
If I uncomment the column type definition, it stores nulls correctly.
How to keep the automatic JSON data type and store NULL correctly from the model?