Skip to content

Commit df0771f

Browse files
committed
Merge pull request #1432 from alcaeus/fix-embedded-fieldname
Fix field name usage when fixing embedded document ownership
2 parents 95a2f3a + 0cff571 commit df0771f

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

CHANGELOG-1.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ All issues and pull requests in this release may be found under the
2323
* [#1416](https://github.com/doctrine/mongodb-odm/pull/1416) fixes name resolution when priming references contained in embedded documents.
2424
* [#1417](https://github.com/doctrine/mongodb-odm/pull/1417) fixes unserializing PersistentCollection objects contained in documents.
2525
* [#1431](https://github.com/doctrine/mongodb-odm/pull/1431) fixes potential object hash collisions with embedded documents by keeping a copy of the document in UnitOfWork.
26+
* [#1432](https://github.com/doctrine/mongodb-odm/pull/1432) fixes the usage of embedded document field names when fixing document ownership.
2627

2728
1.0.5 (2016-02-16)
2829
------------------

lib/Doctrine/ODM/MongoDB/UnitOfWork.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,8 @@ private function computeAssociationChanges($parentDocument, array $assoc, $value
968968
if ($knownParent && $knownParent !== $parentDocument) {
969969
$entry = clone $entry;
970970
if ($assoc['type'] === ClassMetadata::ONE) {
971-
$class->setFieldValue($parentDocument, $assoc['name'], $entry);
972-
$this->setOriginalDocumentProperty(spl_object_hash($parentDocument), $assoc['name'], $entry);
971+
$class->setFieldValue($parentDocument, $assoc['fieldName'], $entry);
972+
$this->setOriginalDocumentProperty(spl_object_hash($parentDocument), $assoc['fieldName'], $entry);
973973
} else {
974974
// must use unwrapped value to not trigger orphan removal
975975
$unwrappedValue[$key] = $entry;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
4+
5+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
6+
use Doctrine\ODM\MongoDB\Tests\BaseTest;
7+
use PHPUnit_Framework_Error_Notice;
8+
9+
class GH1428Test extends BaseTest
10+
{
11+
public function testShortNameLoss_OnReplacingMiddleEmbeddedDoc_OfNestedEmbedding()
12+
{
13+
$owner = new GH1428Document();
14+
$nestedEmbedded = new GH1428NestedEmbeddedDocument();
15+
$this->dm->persist($owner);
16+
$this->dm->flush();
17+
18+
$owner->embedded = new GH1428EmbeddedDocument();
19+
$owner->embedded->nestedEmbedded = $nestedEmbedded;
20+
$this->dm->flush();
21+
22+
$owner->embedded = new GH1428EmbeddedDocument();
23+
$owner->embedded->nestedEmbedded = $nestedEmbedded;
24+
25+
try {
26+
$this->dm->flush();
27+
$this->assertTrue(true);
28+
} catch (PHPUnit_Framework_Error_Notice $ex) {
29+
$this->fail($ex);
30+
}
31+
}
32+
}
33+
34+
/** @ODM\Document */
35+
class GH1428Document
36+
{
37+
/** @ODM\Id */
38+
public $id;
39+
40+
/** @ODM\EmbedOne(targetDocument="GH1428EmbeddedDocument") */
41+
public $embedded;
42+
}
43+
44+
/** @ODM\EmbeddedDocument */
45+
class GH1428EmbeddedDocument
46+
{
47+
/** @ODM\EmbedOne(targetDocument="GH1428NestedEmbeddedDocument", name="shortNameThatDoesntExist") */
48+
public $nestedEmbedded;
49+
}
50+
51+
/** @ODM\EmbeddedDocument */
52+
class GH1428NestedEmbeddedDocument
53+
{
54+
}

0 commit comments

Comments
 (0)