Преглед на файлове

[DoctrineBundle] Fixed the Registry::getEntityManagerForObject method

Christophe Coevoet преди 14 години
родител
ревизия
f21dc42358
променени са 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;
             }
         }