repository check

This commit is contained in:
yuri
2018-03-28 15:55:12 +03:00
parent ab18f72f69
commit 933456ecdf
4 changed files with 17 additions and 0 deletions
+10
View File
@@ -29,6 +29,8 @@
namespace Espo\ORM;
use \Espo\Core\Exceptions\Error;
class EntityManager
{
@@ -158,6 +160,10 @@ class EntityManager
public function getEntity($name, $id = null)
{
if (!$this->hasRepository($name)) {
throw new Error("ORM: Repository '{$name}' does not exist.");
}
return $this->getRepository($name)->get($id);
}
@@ -175,6 +181,10 @@ class EntityManager
public function getRepository($name)
{
if (!$this->hasRepository($name)) {
throw new Error("ORM: Repository '{$name}' does not exist.");
}
if (empty($this->repositoryHash[$name])) {
$this->repositoryHash[$name] = $this->repositoryFactory->create($name);
}
+1
View File
@@ -28,6 +28,7 @@
************************************************************************/
namespace Espo\ORM;
abstract class Repository
{
/**
@@ -143,6 +143,9 @@ class EmailAddress extends \Espo\Core\ORM\Repositories\RDB
$sth->execute();
while ($row = $sth->fetch()) {
if (!empty($row['entityType']) && !empty($row['entityId'])) {
if (!$this->getEntityManager()->hasRepository($row['entityType'])) {
return;
}
if ($onlyName) {
$entity = $this->getEntityManager()->getRepository($row['entityType'])
->select(['id', 'name'])
@@ -137,6 +137,9 @@ class PhoneNumber extends \Espo\Core\ORM\Repositories\RDB
$sth->execute();
while ($row = $sth->fetch()) {
if (!empty($row['entityType']) && !empty($row['entityId'])) {
if (!$this->getEntityManager()->hasRepository($row['entityType'])) {
return;
}
$entity = $this->getEntityManager()->getEntity($row['entityType'], $row['entityId']);
if ($entity) {
return $entity;