Skip to content
Permalink
Browse files

Implemented marshalling with fieldList for _joinData

  • Loading branch information...
lorenzo committed Jul 12, 2014
1 parent 86c10b3 commit 69fbcc40088aeecbe8ac3e16f17821be9700f46d
Showing with 61 additions and 3 deletions.
  1. +2 −2 src/ORM/Marshaller.php
  2. +59 −1 tests/TestCase/ORM/MarshallerTest.php
@@ -192,8 +192,8 @@ protected function _belongsToMany(Association $assoc, array $data, $options = []
$jointMarshaller = $joint->marshaller();
$nested = [];
if (isset($associated['_joinData']['associated'])) {
$nested = ['associated' => (array)$associated['_joinData']['associated']];
if (isset($associated['_joinData'])) {
$nested = (array)$associated['_joinData'];
}
foreach ($records as $i => $record) {
@@ -1115,7 +1115,7 @@ public function testAssociatoinsFieldList() {
}
/**
* Tests merging data into an associated entity
* Tests merging associated data with a fieldList
*
* @return void
*/
@@ -1153,4 +1153,62 @@ public function testMergeAssociationWithfieldList() {
$this->assertTrue($entity->dirty('user'));
}
/**
* Test marshalling nested associations on the _joinData structure
* while having a fieldList
*
* @return void
*/
public function testJoinDataWhiteList() {
$data = [
'title' => 'My title',
'body' => 'My content',
'author_id' => 1,
'tags' => [
[
'tag' => 'news',
'_joinData' => [
'active' => 1,
'crazy' => 'data',
'user' => ['username' => 'Bill'],
]
],
[
'tag' => 'cakephp',
'_joinData' => [
'active' => 0,
'crazy' => 'stuff',
'user' => ['username' => 'Mark'],
]
],
],
];
$articlesTags = TableRegistry::get('ArticlesTags');
$articlesTags->belongsTo('Users');
$marshall = new Marshaller($this->articles);
$result = $marshall->one($data, [
'associated' => [
'Tags._joinData' => ['fieldList' => ['active', 'user']],
'Tags._joinData.Users'
]
]);
$this->assertInstanceOf(
'Cake\ORM\Entity',
$result->tags[0]->_joinData->user,
'joinData should contain a user entity.'
);
$this->assertEquals('Bill', $result->tags[0]->_joinData->user->username);
$this->assertInstanceOf(
'Cake\ORM\Entity',
$result->tags[1]->_joinData->user,
'joinData should contain a user entity.'
);
$this->assertEquals('Mark', $result->tags[1]->_joinData->user->username);
$this->assertNull($result->tags[0]->_joinData->crazy);
$this->assertNull($result->tags[1]->_joinData->crazy);
}
}

0 comments on commit 69fbcc4

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