diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index f31c11eef12..da26a6346e0 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -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); @@ -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']); @@ -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) { diff --git a/tests/TestCase/ORM/CompositeKeysTest.php b/tests/TestCase/ORM/CompositeKeysTest.php index 255a3278e9c..ca9cbb5985e 100644 --- a/tests/TestCase/ORM/CompositeKeysTest.php +++ b/tests/TestCase/ORM/CompositeKeysTest.php @@ -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]); @@ -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); } diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index 2851fa1e589..48233a7c83b 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -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);