Hi,
I have a Mysql DB with JSON FIELDS for example:
Code:
CREATE TABLE `contents` (
`content_id` int(11) NOT NULL AUTO_INCREMENT,
`gallery` json DEFAULT NULL
)
My content Entity is:
<?php
namespace App\Entities;
use CodeIgniter\Entity\Entity;
class Content extends Entity
{
protected $casts = [
'content_id' => 'integer',
'gallery' => 'json'
];
}
My model
<?php
namespace App\Models;
use CodeIgniter\Model;
class ContentModel extends Model
{
...
protected $returnType = \App\Entities\Content::class;
public function customFind($where = [], $select = []) {
$bulder = $this->db->table("contents");
$bulder->select("*");
return $bulder->get()->getResultObject(\App\Entities\Content::class);
}
}
When in Codegniter call method "getResultObject" and set the cast of attibute "gallery" call function:
json_encode("gallery", JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR)
But the field "gallery" is alredy encoded in the the $builder result.
Is it possible to introduce a check in the class "JsonCast" to see if the string isn't already encoded?
Or introduce in the getResultObject method an options for "skip" _set trasformation of specific field ex: getResultObject(\App\Entities\Content::class, ["skipSet"=>["gallery"]])
thank you!