Skip to content

Commit

Permalink
Merge pull request #8882 from cakephp/marshaller-overwrite
Browse files Browse the repository at this point in the history
Merge prefixed data in when marshalling instead of overwriting
  • Loading branch information
markstory committed May 27, 2016
2 parents d35a88c + cda4d86 commit 7a5364a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ORM/Marshaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ protected function _prepareDataAndOptions($data, $options)

$tableName = $this->_table->alias();
if (isset($data[$tableName])) {
$data = $data[$tableName];
$data += $data[$tableName];
unset($data[$tableName]);
}

$data = new ArrayObject($data);
Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase/ORM/MarshallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public function testOneAccessibleFieldsOptionForAssociations()
public function testOneWithAdditionalName()
{
$data = [
'title' => 'Original Title',
'Articles' => [
'title' => 'My title',
'body' => 'My content',
Expand All @@ -376,7 +377,8 @@ public function testOneWithAdditionalName()
$this->assertInstanceOf('Cake\ORM\Entity', $result);
$this->assertTrue($result->dirty(), 'Should be a dirty entity.');
$this->assertTrue($result->isNew(), 'Should be new');
$this->assertEquals($data['Articles']['title'], $result->title);
$this->assertFalse($result->has('Articles'), 'No prefixed field.');
$this->assertEquals($data['title'], $result->title, 'Data from prefix should be merged.');
$this->assertEquals($data['Articles']['user']['username'], $result->user->username);
}

Expand Down

0 comments on commit 7a5364a

Please sign in to comment.