Skip to content

Intelligent model reloading after save#63

Merged
DarkSide666 merged 7 commits intodevelopfrom
feature/intelligent-model-reloading-after-save
Jul 21, 2016
Merged

Intelligent model reloading after save#63
DarkSide666 merged 7 commits intodevelopfrom
feature/intelligent-model-reloading-after-save

Conversation

@romaninsh
Copy link
Copy Markdown
Member

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.

Comment thread docs/expressions.rst

echo $m['a']+$m['b']; // outputs 14

.. note:: If your model is using reload_after_save, but you wish to insert
Copy link
Copy Markdown
Member

@DarkSide666 DarkSide666 Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}

Copy link
Copy Markdown
Member Author

@romaninsh romaninsh Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/Model.php
$this->hook('afterInsert', [$this->id]);

//$this->hook('beforeInsert', array(&$source));
if ($this->reload_after_save !== false) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't here be ===true instead of !==false ?

Copy link
Copy Markdown
Member Author

@romaninsh romaninsh Jul 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!== false is correct. will reload if it's either null or true. As per doc insert() always reloads unless switched off.

@DarkSide666 DarkSide666 merged commit 1b9c538 into develop Jul 21, 2016
@DarkSide666 DarkSide666 deleted the feature/intelligent-model-reloading-after-save branch July 21, 2016 23:01
@romaninsh romaninsh restored the feature/intelligent-model-reloading-after-save branch August 19, 2016 10:22
@romaninsh romaninsh deleted the feature/intelligent-model-reloading-after-save branch August 19, 2016 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants