Skip to content

Commit

Permalink
Feature/double set then back to reset dirty (#75)
Browse files Browse the repository at this point in the history
* updating changelog

* Fix multiple set on field then restoring original value

* style

* typo
  • Loading branch information
romaninsh authored and DarkSide666 committed Jul 25, 2016
1 parent 94d9327 commit 249f64b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
This is our first maintenance release that solves several important
issues.

*
* Added support for automated model reloading after save().
* Added documentaiton sections for Advanced Topics with tips and tricks
* Added documentation sections for Advanced Topics with tips and tricks
* how to implement [soft-delete](http://agile-data.readthedocs.io/en/develop/advanced.html#soft-delete), [audit](http://agile-data.readthedocs.io/en/develop/advanced.html#audit-fields)
* how to [override default method actions](http://agile-data.readthedocs.io/en/develop/model.html?highlight=hook#how-to-prevent-action), e.g. [delete()](shttp://agile-data.readthedocs.io/en/develop/advanced.html#soft-delete-that-overrides-default-delete)
* how to [verify updates](http://agile-data.readthedocs.io/en/develop/model.html?highlight=hook#how-to-verify-updates)
Expand All @@ -18,8 +17,8 @@ issues.
This is our first stable version release for Agile Data. The class and
method structure has sufficiently matured and will not be changed much
anymore. Further 1.0.x versions will be focused on increasing stability
and bugfixes. Versions 1.x will add more notable features, but will
if any incompatibilities will occur, they will be mentioned in release
and bugfixes. Versions 1.x will add more notable features, but if any
incompatibilities will occur, then they will be mentioned in release
notes and CHAGELOG.md

* Rewrote QuickStart guide and README.md, so everyone should re-read them
Expand Down
6 changes: 2 additions & 4 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,15 @@ public function set($field, $value = null)

if (array_key_exists($field, $this->dirty) && $this->dirty[$field] === $value) {
unset($this->dirty[$field]);
$this->data[$field] = $value;
} else {
} elseif (!array_key_exists($field, $this->dirty)) {
$this->dirty[$field] =
array_key_exists($field, $this->data) ?
$this->data[$field] :
(
$f_object ? $f_object->default : null
);

$this->data[$field] = $value;
}
$this->data[$field] = $value;

if ($field === $this->id_field) {
$this->id = $value;
Expand Down
4 changes: 4 additions & 0 deletions tests/BusinessModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function testDirty()
$m['name'] = 10;
$this->assertEquals(['name' => 5], $m->dirty);

$m['name'] = 15;
$this->assertEquals(['name' => 5], $m->dirty);


$m['name'] = 5;
$this->assertEquals([], $m->dirty);

Expand Down

0 comments on commit 249f64b

Please sign in to comment.