1
0
mirror of synced 2025-02-21 22:53:15 +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,11 +916,11 @@ 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
@ -1527,23 +1523,24 @@ 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;
} }
}
if (count($filterClauses)) {
if ($condSql) {
$condSql .= ' AND ';
} }
$condSql .= implode(' AND ', $filterClauses); if (count($filterClauses)) {
if ($condSql) {
$condSql .= ' AND ';
}
$condSql .= implode(' AND ', $filterClauses);
}
} }
if ($condSql) { if ($condSql) {