Permalink
Browse files

added Registry::getEntityManagerForObject() to conveniently get the e…

…ntity manager associated with a given Entity
  • Loading branch information...
1 parent bccdc15 commit 926b0cd91f265759305cac3458df9530eedefae0 @fabpot fabpot committed Jul 6, 2011
Showing with 18 additions and 0 deletions.
  1. +18 −0 Registry.php
View
@@ -216,4 +216,22 @@ public function getRepository($entityName, $entityManagerName = null)
{
return $this->getEntityManager($entityManagerName)->getRepository($entityName);
}
+
+ /**
+ * Gets the entity manager associated with a given object.
+ *
+ * @param object $object A Doctrine Entity
+ *
+ * @return EntityManager|null
+ */
+ public function getEntityManagerForObject($object)
+ {
+ foreach ($this->entityManagers as $id) {
+ $em = $this->container->get($id);
+
+ if ($em->getConfiguration()->getMetadataDriverImpl()->isTransient($object)) {
+ return $em;
+ }
+ }
+ }
}

0 comments on commit 926b0cd

Please sign in to comment.