From a67d43edbba39d9d96dfac69a2b69e3f183cb6c1 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 10 Jun 2014 10:24:30 +0300 Subject: [PATCH] fix select related cound with joins --- application/Espo/ORM/DB/Mapper.php | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/application/Espo/ORM/DB/Mapper.php b/application/Espo/ORM/DB/Mapper.php index 2866167245..d2b2f17617 100644 --- a/application/Espo/ORM/DB/Mapper.php +++ b/application/Espo/ORM/DB/Mapper.php @@ -282,27 +282,7 @@ abstract class Mapper implements IMapper if (!$totalCount) { $selectPart = $this->getSelect($relEntity); $joinsPart = $this->getBelongsToJoins($relEntity); - $orderPart = $this->getOrder($relEntity, $orderBy, $order); - - if (!empty($joins) && is_array($joins)) { - $joinsRelated = $this->getJoins($relEntity, $joins, false, $joinConditions); - if (!empty($joinsRelated)) { - if (!empty($joinsPart)) { - $joinsPart .= ' '; - } - $joinsPart .= $joinsRelated; - } - } - - if (!empty($leftJoins) && is_array($leftJoins)) { - $joinsRelated = $this->getJoins($relEntity, $leftJoins, true, $joinConditions); - if (!empty($joinsRelated)) { - if (!empty($joinsPart)) { - $joinsPart .= ' '; - } - $joinsPart .= $joinsRelated; - } - } + $orderPart = $this->getOrder($relEntity, $orderBy, $order); } else { $selectPart = $this->getAggregationSelect($relEntity, 'COUNT', 'id'); @@ -312,6 +292,26 @@ abstract class Mapper implements IMapper $limit = null; } + if (!empty($joins) && is_array($joins)) { + $joinsRelated = $this->getJoins($relEntity, $joins, false, $joinConditions); + if (!empty($joinsRelated)) { + if (!empty($joinsPart)) { + $joinsPart .= ' '; + } + $joinsPart .= $joinsRelated; + } + } + + if (!empty($leftJoins) && is_array($leftJoins)) { + $joinsRelated = $this->getJoins($relEntity, $leftJoins, true, $joinConditions); + if (!empty($joinsRelated)) { + if (!empty($joinsPart)) { + $joinsPart .= ' '; + } + $joinsPart .= $joinsRelated; + } + } + $relType = $relOpt['type']; $keySet = $this->getKeys($entity, $relationName);