Skip to content

Commit 33e0bc0

Browse files
committed
Fix internal query that does not work when using discriminatorMap and no targetDocument.
1 parent cbf45c3 commit 33e0bc0

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private function generateHydratorClass(ClassMetadata $class, $hydratorClassName,
268268
\$className = \$mapping['targetDocument'];
269269
\$targetClass = \$this->dm->getClassMetadata(\$mapping['targetDocument']);
270270
\$mappedByMapping = \$targetClass->fieldMappings[\$mapping['mappedBy']];
271-
\$mappedByFieldName = isset(\$mappedByMapping['simple']) && \$mappedByMapping['simple'] ? \$mapping['mappedBy'] : \$mapping['mappedBy'].'.id';
271+
\$mappedByFieldName = isset(\$mappedByMapping['simple']) && \$mappedByMapping['simple'] ? \$mapping['mappedBy'] : \$mapping['mappedBy'].'.\$id';
272272
\$criteria = array_merge(
273273
array(\$mappedByFieldName => \$data['_id']),
274274
isset(\$this->class->fieldMappings['%2\$s']['criteria']) ? \$this->class->fieldMappings['%2\$s']['criteria'] : array()

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ private function loadReferenceManyCollectionInverseSide(PersistentCollection $co
694694
$ownerClass = $this->dm->getClassMetadata(get_class($owner));
695695
$targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
696696
$mappedByMapping = $targetClass->fieldMappings[$mapping['mappedBy']];
697-
$mappedByFieldName = isset($mappedByMapping['simple']) && $mappedByMapping['simple'] ? $mapping['mappedBy'] : $mapping['mappedBy'].'.id';
697+
$mappedByFieldName = isset($mappedByMapping['simple']) && $mappedByMapping['simple'] ? $mapping['mappedBy'] : $mapping['mappedBy'].'.$id';
698698
$criteria = array_merge(
699699
array($mappedByFieldName => $ownerClass->getIdentifierObject($owner)),
700700
isset($mapping['criteria']) ? $mapping['criteria'] : array()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
4+
5+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
6+
7+
class GH426Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
8+
{
9+
public function testTest()
10+
{
11+
$form = new GH426Form();
12+
$form->fields[] = new GH426Field($form);
13+
$form->fields[] = new GH426Field($form);
14+
15+
$this->dm->persist($form);
16+
$this->dm->flush();
17+
$this->dm->clear();
18+
19+
$form = $this->dm->find('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH426Form', $form->id);
20+
21+
$this->assertEquals(2, $form->fields->count());
22+
$this->assertSame($form->fields[0], $form->firstField);
23+
$this->assertSame($form->fields[1], $form->lastField);
24+
$this->assertInstanceOf('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH426Field', $form->firstField);
25+
$this->assertInstanceOf('Doctrine\ODM\MongoDB\Tests\Functional\Ticket\GH426Field', $form->lastField);
26+
}
27+
}
28+
29+
/** @ODM\Document */
30+
class GH426Form
31+
{
32+
/** @ODM\Id */
33+
public $id;
34+
35+
/** @ODM\ReferenceMany(targetDocument="GH426Field", mappedBy="form", cascade={"all"}) */
36+
public $fields = array();
37+
38+
/** @ODM\ReferenceOne(targetDocument="GH426Field", mappedBy="form", sort={"_id":1}) */
39+
public $firstField;
40+
41+
/** @ODM\ReferenceOne(targetDocument="GH426Field", mappedBy="form", sort={"_id":-1}) */
42+
public $lastField;
43+
}
44+
45+
/** @ODM\Document */
46+
class GH426Field
47+
{
48+
/** @ODM\Id */
49+
public $id;
50+
51+
/** @ODM\ReferenceOne(inversedBy="fields", discriminatorMap={"f":"GH426Form"}, discriminatorField="type", cascade={"all"}) */
52+
public $form;
53+
54+
public function __construct(GH426Form $form)
55+
{
56+
$this->form = $form;
57+
}
58+
}

0 commit comments

Comments
 (0)