I have a problem, when I try to handle models with disabled events.
When I take the model from documentation:
<?php
class Robots extends Phalcon\Mvc\Model
{
public $id;
public $name;
public $status;
public function beforeSave()
{
//Convert the array into a string
$this->status = join(',', $this->status);
}
public function afterFetch()
{
//Convert the string to an array
$this->status = explode(',', $this->status);
}
}
Now in my controller:
\Phalcon\Mvc\Model::setup(array('events' => false));
$robot = Robots::findFirstById(1);
$robot->name = 'Mecha';
$robot->save();
\Phalcon\Mvc\Model::setup(array('events' => true));
The problem now is, that the afterFetch method is called, but the beforeSave not, so the status field is saved as array and php sends a notice message.
My workaround is, to call manually the beforeSave method, but for complex data change processes this can become unmaneagable.
Have someone a good practicable solution?