From 1092b17a136cb45da40f990cf80f34962293015d Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 17 Jun 2024 12:50:10 +0300 Subject: [PATCH] orm mapper: check deleted when update --- application/Espo/ORM/Mapper/BaseMapper.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/application/Espo/ORM/Mapper/BaseMapper.php b/application/Espo/ORM/Mapper/BaseMapper.php index 5e9a53a182..f88736247a 100644 --- a/application/Espo/ORM/Mapper/BaseMapper.php +++ b/application/Espo/ORM/Mapper/BaseMapper.php @@ -837,6 +837,8 @@ class BaseMapper implements RDBMapper $key = $relationName . 'Id'; $foreignRelationName = $this->getRelationParam($entity, $relationName, 'foreign'); + // @todo Check 'deleted' attribute exists. Apply for all usages further. + if ( $foreignRelationName && $this->getRelationParam($relEntity, $foreignRelationName, 'type') === Entity::HAS_ONE @@ -1425,13 +1427,16 @@ class BaseMapper implements RDBMapper return; } + $where = [self::ATTR_ID => $entity->getId()]; + + if ($entity->hasAttribute(self::ATTR_DELETED)) { + $where[self::ATTR_DELETED] = false; + } + $query = UpdateBuilder::create() ->in($entity->getEntityType()) ->set($valueMap) - ->where([ - self::ATTR_ID => $entity->getId(), - self::ATTR_DELETED => false, - ]) + ->where($where) ->build(); $this->queryExecutor->execute($query); @@ -1500,7 +1505,7 @@ class BaseMapper implements RDBMapper */ public function delete(Entity $entity): void { - if (!$entity->hasAttribute('deleted')) { + if (!$entity->hasAttribute(self::ATTR_DELETED)) { $this->deleteFromDb($entity->getEntityType(), $entity->getId()); return;