I have next model:
class Team extends \Phalcon\Mvc\Model
{
/** @var int */
public $id;
/** @var array */
public $players;
public function beforeSave()
{
$this->players = serialize($this->players);
}
public function afterFetch()
{
$this->players = unserialize($this->players);
}
}
When I save item and get them via Team::findFirst() then array deserializes as expected:
$team = new Team();
$team->players = [777,888];
$team->save();
$id = $team->id; // 1
json_encode(Team::findFirst($id)); // {"id":"1","players":[777,888]}
But when I use Team::find() to obtain collection of objects, behavior is different, array is not deserialized:
json_encode(Team::find($id)->toArray()); // [{"id":"1","players":"a:2:{i:0;i:777;i:1;i:888;}"}]
How to tell Phalcon to deserialize it on collection fetch like this?