fix select related cound with joins

This commit is contained in:
Yuri Kuznetsov
2014-06-10 10:24:30 +03:00
parent e5762b96d2
commit a67d43edbb
+21 -21
View File
@@ -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);