Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/caaa686d79a5945f5519 to your computer and use it in GitHub Desktop.
Save doctrinebot/caaa686d79a5945f5519 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1441 - https://github.com/doctrine/doctrine2/issues/2068
diff --git a/src/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/src/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
index 2044932..5dea312 100644
--- a/src/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+++ b/src/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
@@ -162,6 +162,14 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
return $this->loadedMetadata[$realClassName];
}
}
+
+ $reflection = new \ReflectionClass($className);
+ $isProxy = $reflection->implementsInterface('Doctrine\ORM\Proxy\Proxy');
+
+ if ($isProxy) {
+ $realClassName = $reflection->getParentClass()
+ ->getName();
+ }
if ($this->cacheDriver) {
if (($cached = $this->cacheDriver->fetch("$realClassName\$CLASSMETADATA")) !== false) {
@@ -259,7 +267,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
}
continue;
}
-
+
$class = $this->newClassMetadataInstance($className);
if ($parent) {
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\UnitOfWork;
require_once __DIR__ . '/../../../TestInit.php';
class DDC1441Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1441File'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1441Picture'),
));
} catch(\Exception $ignored) {}
}
public function testFailingCase()
{
// Remove all data so we can count in the end
$this->_em->createQuery("DELETE FROM " . __NAMESPACE__ . '\DDC1441Picture')->execute();
$this->_em->createQuery("DELETE FROM " . __NAMESPACE__ . '\DDC1441File')->execute();
// Persist new objects
$file = new DDC1441File;
$picture = new DDC1441Picture;
$picture->setFile($file);
$this->_em->persist($picture);
$this->_em->flush();
$this->_em->clear();
// Load picture with unloaded file proxy object
$picture = $this->_em->find(__NAMESPACE__ . '\DDC1441Picture', $picture->getPictureId());
// Unset the metadata for proxy object, partially simulates clean environment
// e.g. when serialized $pic is unwrapped in another request
$file = $picture->getFile();
$proxyClassName = get_class($file);
$this->_em->getMetadataFactory()
->setMetadataFor($proxyClassName, null);
$this->_em->merge($picture);
}
}
/**
* @Entity
*/
class DDC1441Picture
{
/**
* @Column(name="picture_id", type="integer")
* @Id @GeneratedValue
*/
private $pictureId;
/**
* @ManyToOne(targetEntity="DDC1441File", cascade={"persist", "remove", "merge"})
* @JoinColumns({
* @JoinColumn(name="file_id", referencedColumnName="file_id")
* })
*/
private $file;
/**
* Get pictureId
*/
public function getPictureId()
{
return $this->pictureId;
}
/**
* Set file
*/
public function setFile($value = null)
{
$this->file = $value;
}
/**
* Get file
*/
public function getFile()
{
return $this->file;
}
}
/**
* @Entity
*/
class DDC1441File
{
/**
* @Column(name="file_id", type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public $fileId;
/**
* Get fileId
*/
public function getFileId()
{
return $this->fileId;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment