Intelligent model reloading after save#63
Conversation
|
|
||
| echo $m['a']+$m['b']; // outputs 14 | ||
|
|
||
| .. note:: If your model is using reload_after_save, but you wish to insert |
There was a problem hiding this comment.
What if I want to update without reload and model is using reload_after_save ? Is that possible? Like ->saveAndUnload() in atk.
Method like this could be handy because most of the time decision do I need to reload or not can be defined only shortly before calling save() not when I initialize Model:
public function saveWithoutReload($data = []) {
$backup = $this->reload_after_save;
$this->reload_after_save = false;
$this->save($data);
$this->reload_after_save = backup;
}
There was a problem hiding this comment.
Answered here: https://github.com/atk4/data/pull/65/files#diff-954e56aad15105e727c7776fcd9ee369R183,
in short - NO but will add later.
| $this->hook('afterInsert', [$this->id]); | ||
|
|
||
| //$this->hook('beforeInsert', array(&$source)); | ||
| if ($this->reload_after_save !== false) { |
There was a problem hiding this comment.
shouldn't here be ===true instead of !==false ?
There was a problem hiding this comment.
!== false is correct. will reload if it's either null or true. As per doc insert() always reloads unless switched off.
When saving the model in Agile Data some field values may not be "true" after save, such as SQL expressions or fields that have default values in the database.
This PR implements intelligent reloading of the models after they are saved. Includes docs.