Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed DDC-1441 unsing doctrine-common ClassUtils getRealClass() method #332

Closed
wants to merge 1 commit into from

2 participants

@gedrox

Fixes http://www.doctrine-project.org/jira/browse/DDC-1441 using helpers from doctrine/common introduced by version 2.2.

@stof

See #315 which does this for all places instead of doing it only in one place

@gedrox

Yes, closing this for #315 which fixes the DDC-1441 as well.

@gedrox gedrox closed this
@jwage jwage referenced this pull request in doctrine/mongodb-odm
Open

Bug fix: Allow loading of metadata for Proxies #211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
@@ -26,7 +26,8 @@
Doctrine\ORM\Events,
Doctrine\Common\Persistence\Mapping\RuntimeReflectionService,
Doctrine\Common\Persistence\Mapping\ReflectionService,
- Doctrine\Common\Persistence\Mapping\ClassMetadataFactory as ClassMetadataFactoryInterface;
+ Doctrine\Common\Persistence\Mapping\ClassMetadataFactory as ClassMetadataFactoryInterface,
+ Doctrine\Common\Util\ClassUtils;
/**
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
@@ -155,7 +156,7 @@ private function initialize()
public function getMetadataFor($className)
{
if ( ! isset($this->loadedMetadata[$className])) {
- $realClassName = $className;
+ $realClassName = ClassUtils::getRealClass($className);
// Check for namespace alias
if (strpos($className, ':') !== false) {
View
114 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1441Test.php
@@ -0,0 +1,114 @@
+<?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;
+ }
+}
Something went wrong with that request. Please try again.