Переглянути джерело

merged branch stof/registry (PR #1600)

Commits
-------

7517fa4 [DoctrineBundle] Fixed the transient test
f21dc42 [DoctrineBundle] Fixed the Registry::getEntityManagerForObject method

Discussion
----------

[DoctrineBundle] Fixed the Registry::getEntityManagerForObject method

This fixes the Registry::getEntityManagerForObject implementation. Doctrine expects the entity class name, not the object. The current code throw a Fatal Error.
Fabien Potencier 14 роки тому
батько
коміт
32ae39e896
1 змінених файлів з 9 додано та 1 видалено
  1. 9 1
      src/Symfony/Bundle/DoctrineBundle/Registry.php

+ 9 - 1
src/Symfony/Bundle/DoctrineBundle/Registry.php

@@ -16,6 +16,7 @@ use Symfony\Bridge\Doctrine\RegistryInterface;
 use Doctrine\DBAL\Connection;
 use Doctrine\ORM\Configuration;
 use Doctrine\ORM\ORMException;
+use Doctrine\ORM\Proxy\Proxy;
 
 /**
  * References all Doctrine connections and entity managers in a given Container.
@@ -226,10 +227,17 @@ class Registry implements RegistryInterface
      */
     public function getEntityManagerForObject($object)
     {
+        if ($object instanceof Proxy) {
+            $proxyClass = new \ReflectionClass($object);
+            $class = $proxyClass->getParentClass()->getName();
+        } else {
+            $class = get_class($object);
+        }
+
         foreach ($this->entityManagers as $id) {
             $em = $this->container->get($id);
 
-            if ($em->getConfiguration()->getMetadataDriverImpl()->isTransient($object)) {
+            if (!$em->getConfiguration()->getMetadataDriverImpl()->isTransient($class)) {
                 return $em;
             }
         }