1
0
mirror of synced 2025-02-22 15:13:13 +03:00

DDC-551 - rework walker filtering

This commit is contained in:
Benjamin Eberlei 2011-12-11 21:14:09 +01:00
parent ad6130b02d
commit b6d776f75d

View File

@ -269,7 +269,7 @@ class SqlWalker implements TreeWalker
} }
// Add filters on the root class // Add filters on the root class
if ('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { if ($filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) {
$sqlParts[] = $filterSql; $sqlParts[] = $filterSql;
} }
@ -853,10 +853,6 @@ class SqlWalker implements TreeWalker
} }
} }
// Apply the filters
if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) {
$sql .= ' AND ' . $filterExpr;
}
} else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) { } else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) {
// Join relation table // Join relation table
$joinTable = $assoc['joinTable']; $joinTable = $assoc['joinTable'];
@ -920,12 +916,12 @@ class SqlWalker implements TreeWalker
$sql .= $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn; $sql .= $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $relationColumn;
} }
} }
}
// Apply the filters // Apply the filters
if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { if ($filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) {
$sql .= ' AND ' . $filterExpr; $sql .= ' AND ' . $filterExpr;
} }
}
// Handle WITH clause // Handle WITH clause
if (($condExpr = $join->conditionalExpression) !== null) { if (($condExpr = $join->conditionalExpression) !== null) {
@ -1527,13 +1523,13 @@ class SqlWalker implements TreeWalker
$condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : ''; $condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : '';
$discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_rootAliases); $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->_rootAliases);
// Apply the filters for all entities in FROM if ($this->_em->hasFilters()) {
$filterClauses = array(); $filterClauses = array();
foreach ($this->_rootAliases as $dqlAlias) { foreach ($this->_rootAliases as $dqlAlias) {
$class = $this->_queryComponents[$dqlAlias]['metadata']; $class = $this->_queryComponents[$dqlAlias]['metadata'];
$tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias);
if ('' !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { if ($filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) {
$filterClauses[] = $filterExpr; $filterClauses[] = $filterExpr;
} }
} }
@ -1545,6 +1541,7 @@ class SqlWalker implements TreeWalker
$condSql .= implode(' AND ', $filterClauses); $condSql .= implode(' AND ', $filterClauses);
} }
}
if ($condSql) { if ($condSql) {
return ' WHERE ' . (( ! $discrSql) ? $condSql : '(' . $condSql . ') AND ' . $discrSql); return ' WHERE ' . (( ! $discrSql) ? $condSql : '(' . $condSql . ') AND ' . $discrSql);