Open
Description
https://codeigniter4.github.io/CodeIgniter4/models/entities.html#property-casting
The object
handler seems to expect the property to be set to an array.
CodeIgniter4/system/Entity/Cast/ObjectCast.php
Lines 22 to 25 in 0cd3993
CodeIgniter4/tests/system/Entity/EntityTest.php
Lines 439 to 449 in 0cd3993
However, when setting an array, we cannot save that Entity to the database.
$entity = new class () extends Entity {
protected $casts = [
'id' => 'int',
'active' => 'int-bool',
'memo' => 'object', // Use `object` handler
];
};
$model = new class () extends Model {
protected $table = 'users';
protected $allowedFields = [
'username', 'active', 'memo',
];
protected $useTimestamps = true;
};
$entity->fill(['username' => 'johnsmith', 'active' => false, 'memo' => ['foo', 'bar']]);
$model->save($entity); // CodeIgniter\Database\Exceptions\DatabaseException : Operand should contain 1 column(s)
How is this handler used in the first place?