Skip to content

Commit

Permalink
Merge pull request #9389 from cakephp/issue-9381
Browse files Browse the repository at this point in the history
Don't mark null values as dirty when they are still null.
  • Loading branch information
lorenzo committed Sep 1, 2016
2 parents 506eeda + 36052a6 commit 05a37af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ORM/Marshaller.php
Expand Up @@ -552,6 +552,7 @@ public function merge(EntityInterface $entity, array $data, array $options = [])
// the original/updated list could contain references to the
// same objects, even though those objects may have changed internally.
if ((is_scalar($value) && $original === $value) ||
($value === null && $original === $value) ||
(is_object($value) && !($value instanceof EntityInterface) && $original == $value)
) {
continue;
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -1334,6 +1334,31 @@ public function testMergeFalseyValues($value)
$this->assertSame(0, $entity->get('author_id'), 'Value should be zero');
}

/**
* Test merge() doesn't dirty values that were null and are null again.
*
* @return void
*/
public function testMergeUnchangedNullValue()
{
$data = [
'title' => 'My title',
'author_id' => 1,
'body' => null,
];
$marshall = new Marshaller($this->articles);
$entity = new Entity([
'title' => 'Foo',
'body' => null
]);
$entity->accessible('*', true);
$entity->isNew(false);
$entity->clean();
$result = $marshall->merge($entity, $data, []);

$this->assertFalse($entity->dirty('body'), 'unchanged null should not be dirty');
}

/**
* Tests that merge respects the entity accessible methods
*
Expand Down

0 comments on commit 05a37af

Please sign in to comment.