1
0
mirror of synced 2025-02-02 13:31:45 +03:00

#1254 DDC-3500 - fixed duplicate JOIN aliases in CTI + WITH condition joins

This commit is contained in:
Marco Pivetta 2015-01-18 16:43:31 +01:00
parent 91e5c0d443
commit ee9aebf569

View File

@ -991,26 +991,22 @@ class SqlWalker implements TreeWalker
} }
// Handle WITH clause // Handle WITH clause
$withCondition = (null !== $condExpr) ? ('(' . $this->walkConditionalExpression($condExpr) . ')') : ''; $withCondition = (null === $condExpr) ? '' : ('(' . $this->walkConditionalExpression($condExpr) . ')');
if ($targetClass->isInheritanceTypeJoined()) { if ($targetClass->isInheritanceTypeJoined()) {
$ctiJoins = $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias); $ctiJoins = $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias);
// If we have WITH condition, we need to build nested joins for target class table and cti joins // If we have WITH condition, we need to build nested joins for target class table and cti joins
if ($withCondition) { if ($withCondition) {
$sql .= '(' . $targetTableJoin['table'] . $ctiJoins . ') ON ' . $targetTableJoin['condition'] . ' AND ' . $withCondition; $sql .= '(' . $targetTableJoin['table'] . $ctiJoins . ') ON ' . $targetTableJoin['condition'];
} else { } else {
$sql .= $targetTableJoin['table'] . ' ON ' . $targetTableJoin['condition'] . $ctiJoins; $sql .= $targetTableJoin['table'] . ' ON ' . $targetTableJoin['condition'] . $ctiJoins;
} }
} else { } else {
$sql .= $targetTableJoin['table'] . ' ON ' . $targetTableJoin['condition']; $sql .= $targetTableJoin['table'] . ' ON ' . $targetTableJoin['condition'];
if ($withCondition) {
$sql .= ' AND ' . $withCondition;
}
} }
// FIXME: these should either be nested or all forced to be left joins (DDC-XXX) if ($withCondition) {
if ($targetClass->isInheritanceTypeJoined()) { $sql .= ' AND ' . $withCondition;
$sql .= $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias);
} }
// Apply the indexes // Apply the indexes