Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed more Marshaller tests
  • Loading branch information
lorenzo committed Jul 10, 2014
1 parent aea75b9 commit eaa62ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/ORM/Marshaller.php
Expand Up @@ -110,7 +110,7 @@ public function one(array $data, array $options = []) {
$columnType = $schema->columnType($key);
if (isset($propertyMap[$key])) {
$assoc = $propertyMap[$key]['association'];
$nested = $propertyMap[$key]['nested'];
$nested = ['associated' => $propertyMap[$key]['nested']];
$value = $this->_marshalAssociation($assoc, $value, $nested);
} elseif ($columnType) {
$converter = Type::build($columnType);
Expand Down Expand Up @@ -172,6 +172,7 @@ public function many(array $data, array $options = []) {
* @return array An array of built entities.
*/
protected function _belongsToMany(Association $assoc, array $data, $options = []) {
$associated = isset($options['associated']) ? $options['associated'] : [];
$hasIds = array_key_exists('_ids', $data);
if ($hasIds && is_array($data['_ids'])) {
return $this->_loadBelongsToMany($assoc, $data['_ids']);
Expand All @@ -185,8 +186,8 @@ protected function _belongsToMany(Association $assoc, array $data, $options = []
$jointMarshaller = $joint->marshaller();

$nested = [];
if (isset($options['_joinData']['associated'])) {
$nested = (array)$options['_joinData']['associated'];
if (isset($associated['_joinData']['associated'])) {
$nested = ['associated' => (array)$associated['_joinData']['associated']];
}

foreach ($records as $i => $record) {
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/ORM/CompositeKeysTest.php
Expand Up @@ -444,7 +444,7 @@ public function testOneGenerateBelongsToManyEntitiesFromIds() {
'tags' => ['_ids' => [[1, 1], [2, 2], [3, 1]]]
];
$marshall = new Marshaller($articles);
$result = $marshall->one($data, ['SiteTags']);
$result = $marshall->one($data, ['associated' => ['SiteTags']]);

$this->assertCount(3, $result->tags);
$this->assertInstanceOf('Cake\ORM\Entity', $result->tags[0]);
Expand All @@ -457,7 +457,7 @@ public function testOneGenerateBelongsToManyEntitiesFromIds() {
'tags' => ['_ids' => [1, 2, 3]]
];
$marshall = new Marshaller($articles);
$result = $marshall->one($data, ['SiteTags']);
$result = $marshall->one($data, ['associated' => ['SiteTags']]);
$this->assertEmpty($result->tags);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -800,7 +800,7 @@ public function testMergeBelongsToManyJoinData() {
],
];

$options = ['Tags' => ['associated' => ['_joinData']]];
$options = ['associated' => ['Tags' => ['associated' => ['_joinData']]]];
$marshall = new Marshaller($this->articles);
$entity = $marshall->one($data, $options);
$entity->accessible('*', true);
Expand Down

0 comments on commit eaa62ee

Please sign in to comment.