Skip to content

Commit

Permalink
[DoctrineBundle] Fixed the Registry::getEntityManagerForObject method
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Jul 9, 2011
1 parent 2ec3542 commit f21dc42
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Symfony/Bundle/DoctrineBundle/Registry.php
Expand Up @@ -16,6 +16,7 @@
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.
Expand Down Expand Up @@ -226,10 +227,17 @@ public function getRepository($entityName, $entityManagerName = null)
*/
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;
}
}
Expand Down

0 comments on commit f21dc42

Please sign in to comment.