diff --git a/application/Espo/ORM/DB/Mapper.php b/application/Espo/ORM/DB/Mapper.php index fd74258ecb..98a76073c7 100644 --- a/application/Espo/ORM/DB/Mapper.php +++ b/application/Espo/ORM/DB/Mapper.php @@ -74,6 +74,7 @@ abstract class Mapper implements IMapper if ($ps) { foreach ($ps as $row) { $entity = $this->fromRow($entity, $row); + $entity->setAsFetched(); return true; } } @@ -118,8 +119,9 @@ abstract class Mapper implements IMapper if ($this->returnCollection) { $collectionClass = $this->collectionClass; - $entityArr = new $collectionClass($dataArr, $entity->getEntityType(), $this->entityFactory); - return $entityArr; + $collection = new $collectionClass($dataArr, $entity->getEntityType(), $this->entityFactory); + $collection->setAsFetched(); + return $collection; } else { return $dataArr; } @@ -197,6 +199,7 @@ abstract class Mapper implements IMapper foreach ($ps as $row) { if (!$totalCount) { $relEntity = $this->fromRow($relEntity, $row); + $relEntity->setAsFetched(); return $relEntity; } else { return $row['AggregateValue']; @@ -237,13 +240,17 @@ abstract class Mapper implements IMapper if ($relType == IEntity::HAS_ONE) { if (count($resultArr)) { - return $this->fromRow($relEntity, $resultArr[0]); + $relEntity = $this->fromRow($relEntity, $resultArr[0]); + $relEntity->setAsFetched(); + return $relEntity; } return null; } else { if ($this->returnCollection) { $collectionClass = $this->collectionClass; - return new $collectionClass($resultArr, $relEntity->getEntityType(), $this->entityFactory); + $collection = new $collectionClass($resultArr, $relEntity->getEntityType(), $this->entityFactory); + $collection->setAsFetched(); + return $collection; } else { return $resultArr; } @@ -282,7 +289,9 @@ abstract class Mapper implements IMapper } if ($this->returnCollection) { $collectionClass = $this->collectionClass; - return new $collectionClass($resultArr, $relEntity->getEntityType(), $this->entityFactory); + $collection = new $collectionClass($resultArr, $relEntity->getEntityType(), $this->entityFactory); + $collection->setAsFetched(); + return $collection; } else { return $resultArr; } @@ -899,5 +908,3 @@ abstract class Mapper implements IMapper $this->collectionClass = $collectionClass; } } - - diff --git a/application/Espo/ORM/EntityCollection.php b/application/Espo/ORM/EntityCollection.php index ab50a9e6c2..cf4a723c7b 100644 --- a/application/Espo/ORM/EntityCollection.php +++ b/application/Espo/ORM/EntityCollection.php @@ -150,9 +150,6 @@ class EntityCollection implements \Iterator, \Countable, \ArrayAccess, \Seekable $value = $this->container[$offset]; if ($value instanceof Entity) { - if ($this->isFetched) { - $value->setAsFetched(); - } return $value; } else if (is_array($value)) { $this->container[$offset] = $this->buildEntityFromArray($value); diff --git a/application/Espo/ORM/Repositories/RDB.php b/application/Espo/ORM/Repositories/RDB.php index 8db8d537cd..c463e5f851 100644 --- a/application/Espo/ORM/Repositories/RDB.php +++ b/application/Espo/ORM/Repositories/RDB.php @@ -117,7 +117,6 @@ class RDB extends \Espo\ORM\Repository $params = array(); $this->handleSelectParams($params); if ($this->getMapper()->selectById($entity, $id, $params)) { - $entity->setAsFetched(); return $entity; } @@ -253,11 +252,9 @@ class RDB extends \Espo\ORM\Repository return $collection; } else if ($result instanceof EntityCollection) { $collection = $result; - $collection->setAsFetched(); return $collection; } else if ($result instanceof Entity) { $entity = $result; - $entity->setAsFetched(); return $entity; } else { return $result;