Skip to content

Commit

Permalink
Mark fields as not dirty when they are unset.
Browse files Browse the repository at this point in the history
Leaving unset fields as dirty makes entity create null values when
persisted.

Refs #4288
  • Loading branch information
markstory committed Aug 19, 2014
1 parent edd85f5 commit 63e6d38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Datasource/EntityTrait.php
Expand Up @@ -308,6 +308,7 @@ public function unsetProperty($property) {
$property = (array)$property;
foreach ($property as $p) {
unset($this->_properties[$p]);
unset($this->_dirty[$p]);
}

return $this;
Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/ORM/EntityTest.php
Expand Up @@ -287,6 +287,18 @@ public function testUnset() {
$this->assertFalse($entity->has('id'));
}

/**
* Unsetting a property should not mark it as dirty.
*
* @return void
*/
public function testUnsetMakesClean() {
$entity = new Entity(['id' => 1, 'name' => 'bar']);
$this->assertTrue($entity->dirty('name'));
$entity->unsetProperty('name');
$this->assertFalse($entity->dirty('name'), 'Removed properties are not dirty.');
}

/**
* Tests unsetProperty whith multiple properties
*
Expand Down

0 comments on commit 63e6d38

Please sign in to comment.