Skip to content
Permalink
Browse files

Don't emit errors when marhshaller gets a scalar for an association

If associations are patchable, and a scalar value is sent no errors
should be emitted.

Refs #10184
  • Loading branch information...
markstory committed Feb 10, 2017
1 parent 7161157 commit 18117ea52664783472fbfdad9a87e7be9d44d839
Showing with 40 additions and 2 deletions.
  1. +3 −0 src/ORM/Marshaller.php
  2. +37 −2 tests/TestCase/ORM/MarshallerTest.php
@@ -698,6 +698,9 @@ protected function _mergeAssociation($original, $assoc, $value, $options)
if (!$original) {
return $this->_marshalAssociation($assoc, $value, $options);
}
if (!is_array($value)) {
return null;
}
$targetTable = $assoc->target();
$marshaller = $targetTable->marshaller();
@@ -1554,6 +1554,41 @@ public function testMergeCreateAssociation()
$this->assertTrue($entity->user->isNew());
}
/**
* Test merge when an association has been replaced with null
*
* @return void
*/
public function testMergeAssociationNullOut()
{
$user = new Entity([
'id' => 1,
'username' => 'user',
]);
$article = new Entity([
'title' => 'title for post',
'user_id' => 1,
'user' => $user,
]);
$user->accessible('*', true);
$article->accessible('*', true);
$data = [
'title' => 'Chelsea',
'user_id' => '',
'user' => ''
];
$marshall = new Marshaller($this->articles);
$marshall->merge($article, $data, [
'associated' => ['Users']
]);
$this->assertNull($article->user);
$this->assertSame('', $article->user_id);
$this->assertTrue($article->dirty('user'));
}
/**
* Tests merging one to many associations
*
@@ -2571,7 +2606,7 @@ public function testMergeManyFieldList()
*
* @return void
*/
public function testAssociatoinsFieldList()
public function testAssociationsFieldList()
{
$data = [
'title' => 'My title',
@@ -2605,7 +2640,7 @@ public function testAssociatoinsFieldList()
*
* @return void
*/
public function testMergeAssociationWithfieldList()
public function testMergeAssociationWithFieldList()
{
$user = new Entity([
'username' => 'mark',

0 comments on commit 18117ea

Please sign in to comment.
You can’t perform that action at this time.