Skip to content

Commit

Permalink
fixed handling of proxies without an identifier mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Oct 3, 2015
1 parent cb260c5 commit bfd45d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 15 additions & 3 deletions lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,20 @@ protected function createProxyDefinition($className)
{
$classMetadata = $this->documentManager->getClassMetadata($className);

if ($classMetadata->identifier) {
$identifierFields = array($classMetadata->identifier);
$reflectionId = $classMetadata->reflFields[$classMetadata->identifier];
} else {
$identifierFields = array();
$reflectionId = null;
}

return new ProxyDefinition(
ClassUtils::generateProxyClassName($classMetadata->getName(), $this->proxyNamespace),
array($classMetadata->identifier),
$identifierFields,
$classMetadata->reflFields,
$this->createInitializer($classMetadata),
$this->createCloner($classMetadata, $classMetadata->reflFields[$classMetadata->identifier])
$this->createCloner($classMetadata, $reflectionId)
);
}

Expand Down Expand Up @@ -168,7 +176,7 @@ private function createInitializer(ClassMetadata $classMetadata)
*
* @throws \Doctrine\Common\Proxy\Exception\UnexpectedValueException
*/
private function createCloner(ClassMetadata $classMetadata, ReflectionProperty $reflectionId)
private function createCloner(ClassMetadata $classMetadata, ReflectionProperty $reflectionId = null)
{
$className = $classMetadata->getName();
$documentManager = $this->documentManager;
Expand All @@ -181,6 +189,10 @@ private function createCloner(ClassMetadata $classMetadata, ReflectionProperty $
$cloned->__setInitialized(true);
$cloned->__setInitializer(null);

if (!$reflectionId) {
return;
}

$original = $documentManager->find($className, $reflectionId->getValue($cloned));

if (null === $original) {
Expand Down
8 changes: 5 additions & 3 deletions tests/Doctrine/Tests/ODM/PHPCR/Functional/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ public function testChildWithoutId()
$parent = new ParentDoc();
$parent->id = $parentId;


$doc = new DocWithoutId();
$doc->parent = $parent;
$doc->nodename = 'foo';

$this->dm->persist($doc);

$this->dm->flush();
$this->dm->clear();

$parent = $this->dm->find(null, $parentId);
$this->assertInstanceOf('\stdClass', $parent->children[0]);
$doc = $parent->children->current();
$this->assertInstanceOf('Doctrine\Common\Proxy\Proxy', $doc);
$this->assertInstanceOf('Doctrine\Tests\ODM\PHPCR\Functional\DocWithoutId', $doc);
$this->assertEquals('foo', $doc->nodename);
$this->assertInstanceOf('Doctrine\Tests\ODM\PHPCR\Functional\ParentDoc', $doc->parent);
}
}

Expand Down

0 comments on commit bfd45d6

Please sign in to comment.