Describe the bug
Fatal error on call $model->getChangedFields()
To Reproduce
$user = Users::findFirst();
var_dump($user->getSnapshotData()); // output: null
print_r($user->getChangedFields()); // fatal error
Steps to reproduce the behavior:
Fatal error: Uncaught Phalcon\Mvc\Model\Exception: The record doesn't have a valid data snapshot in phalcon/Mvc/Model.zep on line 1520
Expected behavior
empty array output
Details
4.0.0-rc.17.3.9linuxinstalling via package managermysqlThis is the intended behavior. If there is no snapshot, an exception is thrown.
We can change this to return an empty array. This will break backwards compatibility.
@phalcon/core-team Thoughts?
Thanks @niden!
In my opinion this is not the case for throwing an exception.
It would be logical to return an empty array
For getChangedFields to work snapshot is required. If we sent back an empty array the user doesn't know the method isn't working.
If keepSnapshots is true we can return the correct value.
<?php
use Phalcon\Mvc\Model;
class Robots extends Model
{
public function initialize()
{
$this->keepSnapshots(true);
}
}
Maybe we should update the error. "keepSnapshots must be enabled to track changes"
I agree with @ruudboon
Implemented
Most helpful comment
For getChangedFields to work snapshot is required. If we sent back an empty array the user doesn't know the method isn't working.
If keepSnapshots is true we can return the correct value.
Maybe we should update the error. "keepSnapshots must be enabled to track changes"