Skip to content

Commit

Permalink
Merge pull request #4329 from cakephp/issue-4307
Browse files Browse the repository at this point in the history
Fix 0/'0' not being patched properly.
  • Loading branch information
lorenzo committed Aug 22, 2014
2 parents e9dd234 + b2ed6a2 commit 43f0ca0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ORM/Marshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ public function merge(EntityInterface $entity, array $data, array $options = [])
} elseif ($columnType) {
$converter = Type::build($columnType);
$value = $converter->marshal($value);
if ($original == $value) {
$isObject = is_object($value);
if (
(!$isObject && $original === $value) ||
($isObject && $original == $value)
) {
continue;
}
}
Expand Down
28 changes: 28 additions & 0 deletions tests/TestCase/ORM/MarshallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,34 @@ public function testMergeSimple() {
$this->assertFalse($result->isNew(), 'Should not change the entity state');
}

/**
* Provides empty values.
*
* @return array
*/
public function emptyProvider() {
return [
[0],
['0'],
];
}

/**
* Test merging empty values into an entity.
*
* @dataProvider emptyProvider
* @return void
*/
public function testMergeFalseyValues($value) {
$marshall = new Marshaller($this->articles);
$entity = new Entity();
$entity->accessible('*', true);

$entity = $marshall->merge($entity, ['author_id' => $value]);
$this->assertTrue($entity->dirty('author_id'), 'Field should be dirty');
$this->assertSame(0, $entity->get('author_id'), 'Value should be zero');
}

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

0 comments on commit 43f0ca0

Please sign in to comment.