When I updated an OrmModel attribute at first time, I get is_changed() to True and save() update my database. After I do some delayed actions and I need to change again the same attributes with an other value, but I obtain is_changed() to false and save() do nothing but when I dump the OrmModel, the value is modified in lmemory. I there an method to force un clean the record or another soluce ??
$myModel->val='firstvalue'; $myModel->save(); // is OK ... ... << actions >> ... $myModel->val='othervalue'; $myModel->save(); // do nothing on database
I've spend time before post without find a mistake. So, I will check tonight again and use profiler so by using your method. Perharps 'gremlins' are hidden very well.
On a controller, the database is updated with the '4' value, but on a task, only the value '2' is wrote !! The other save() methods are executed but the model has his changed flag modified the dump is also good but the not the database..
Perhaps I must wrap all into a controller and limit statement into task with \Request::forge ?
I noticed that I must use 'from_cache' => false into model::find to work as excepted, but I know understand why. When I show is_changed() state , I get :
echo $obj->is_changed() => false $obj->state= << other state >> echo $obj->is_changed() => true $obj->save() echo $obj->is_changed() => false but nothing on database if I don't use 'from_cache' => false !!
I did some inspection into model.php code and put some outputs protected function update() { // New objects can't be updated, neither can frozen if ($this->is_new()) { return false; }
// Non changed objects don't have to be saved, but return true anyway (no reason to fail) if ( ! $this->is_changed(array_keys(static::properties()))) { echo __METHOD__,' ',__LINE__,' __TRUE',PHP_EOL; return true; }
. . public function is_changed($property = null) { echo '===========>',__METHOD__,' ',__LINE__,print_r($property,true),PHP_EOL; $properties = static::properties(); . . add echo TRUE or FALSE before each return statement of is_changed() method.
My code echo 'is_changed:',$first->is_changed(),PHP_EOL; echo '--------------------------------------',PHP_EOL; $first->save(); die('-------------------------------------');
So "state" is a foreign key to a related table, and your issue is that the foreign key isn't updated if you change the related object and you save the parent, correct?
Are you completely up to date with 1.8? Did you do a composer update to make sure you have all recent updates and fixes?
I've enabled MySQL log, and by CLI, there is no UPDATE statement for the second save() action. Perhaps I must do this by other way, the context execution is no the same and perhaps something is missing in my way to do tasks.