diff --git a/src/ORM/EntityValidator.php b/src/ORM/EntityValidator.php index b427f7d2dbf..6601807c7ea 100644 --- a/src/ORM/EntityValidator.php +++ b/src/ORM/EntityValidator.php @@ -93,7 +93,8 @@ public function one(Entity $entity, $options = []) { } $validator = $association->target()->entityValidator(); - if ($association->type() === Association::ONE_TO_ONE) { + $types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE]; + if (in_array($association->type(), $types)) { $valid = $validator->one($value, $assoc['options']) && $valid; } else { $valid = $validator->many($value, $assoc['options']) && $valid; diff --git a/src/ORM/Marshaller.php b/src/ORM/Marshaller.php index 0f06a80b260..bfd29d82161 100644 --- a/src/ORM/Marshaller.php +++ b/src/ORM/Marshaller.php @@ -132,7 +132,8 @@ public function one(array $data, $include = []) { protected function _marshalAssociation($assoc, $value, $include) { $targetTable = $assoc->target(); $marshaller = $targetTable->marshaller(); - if ($assoc->type() === Association::ONE_TO_ONE) { + $types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE]; + if (in_array($assoc->type(), $types)) { return $marshaller->one($value, (array)$include); } if ($assoc->type() === Association::MANY_TO_MANY) { @@ -327,7 +328,8 @@ protected function _mergeAssociation($original, $assoc, $value, $include) { $targetTable = $assoc->target(); $marshaller = $targetTable->marshaller(); - if ($assoc->type() === Association::ONE_TO_ONE) { + $types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE]; + if (in_array($assoc->type(), $types)) { return $marshaller->merge($original, $value, (array)$include); } if ($assoc->type() === Association::MANY_TO_MANY) { diff --git a/tests/TestCase/ORM/AssociationTest.php b/tests/TestCase/ORM/AssociationTest.php index 6804d84753e..b32588b4918 100644 --- a/tests/TestCase/ORM/AssociationTest.php +++ b/tests/TestCase/ORM/AssociationTest.php @@ -52,7 +52,7 @@ public function setUp() { '\Cake\ORM\Association', [ '_options', 'attachTo', '_joinCondition', 'cascadeDelete', 'isOwningSide', - 'save', 'eagerLoader' + 'save', 'eagerLoader', 'type' ], ['Foo', $config] );