Root selection according other pagination tools
changed root selection in Walkers from looping queryComponents to using $AST->fromClause as other walkers have
This commit is contained in:
parent
114bd2435f
commit
a37f99f242
@ -50,40 +50,24 @@ class CountWalker extends TreeWalkerAdapter
|
||||
throw new \RuntimeException('Cannot count query that uses a HAVING clause. Use the output walkers for pagination');
|
||||
}
|
||||
|
||||
$rootComponents = array();
|
||||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
|
||||
$isParent = array_key_exists('parent', $qComp)
|
||||
&& $qComp['parent'] === null
|
||||
&& $qComp['nestingLevel'] == 0
|
||||
;
|
||||
if ($isParent) {
|
||||
foreach($AST->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) {
|
||||
$isRoot = $identificationVariableDeclaration->rangeVariableDeclaration
|
||||
&& $identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable == $dqlAlias
|
||||
&& $identificationVariableDeclaration->rangeVariableDeclaration->isRoot
|
||||
;
|
||||
if ($isRoot) {
|
||||
$rootComponents[] = array($dqlAlias => $qComp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($rootComponents) > 1) {
|
||||
$queryComponents = $this->_getQueryComponents();
|
||||
// Get the root entity and alias from the AST fromClause
|
||||
$from = $AST->fromClause->identificationVariableDeclarations;
|
||||
if (count($from) > 1) {
|
||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||
}
|
||||
$root = reset($rootComponents);
|
||||
$parentName = key($root);
|
||||
$parent = current($root);
|
||||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName();
|
||||
|
||||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
|
||||
$rootClass = $queryComponents[$rootAlias]['metadata'];
|
||||
$identifierFieldName = $rootClass->getSingleIdentifierFieldName();
|
||||
|
||||
$pathType = PathExpression::TYPE_STATE_FIELD;
|
||||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) {
|
||||
if (isset($rootClass->associationMappings[$identifierFieldName])) {
|
||||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
|
||||
}
|
||||
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName,
|
||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias,
|
||||
$identifierFieldName
|
||||
);
|
||||
$pathExpression->type = $pathType;
|
||||
|
@ -60,37 +60,34 @@ class LimitSubqueryWalker extends TreeWalkerAdapter
|
||||
*/
|
||||
public function walkSelectStatement(SelectStatement $AST)
|
||||
{
|
||||
$parent = null;
|
||||
$parentName = null;
|
||||
$queryComponents = $this->_getQueryComponents();
|
||||
// Get the root entity and alias from the AST fromClause
|
||||
$from = $AST->fromClause->identificationVariableDeclarations;
|
||||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
|
||||
$rootClass = $queryComponents[$rootAlias]['metadata'];
|
||||
$selectExpressions = array();
|
||||
|
||||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
|
||||
foreach ($queryComponents as $dqlAlias => $qComp) {
|
||||
// Preserve mixed data in query for ordering.
|
||||
if (isset($qComp['resultVariable'])) {
|
||||
$selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
|
||||
$parent = $qComp;
|
||||
$parentName = $dqlAlias;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$identifier = $parent['metadata']->getSingleIdentifierFieldName();
|
||||
if (isset($parent['metadata']->associationMappings[$identifier])) {
|
||||
$identifier = $rootClass->getSingleIdentifierFieldName();
|
||||
if (isset($rootClass->associationMappings[$identifier])) {
|
||||
throw new \RuntimeException("Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.");
|
||||
}
|
||||
|
||||
$this->_getQuery()->setHint(
|
||||
self::IDENTIFIER_TYPE,
|
||||
Type::getType($parent['metadata']->getTypeOfField($identifier))
|
||||
Type::getType($rootClass->getTypeOfField($identifier))
|
||||
);
|
||||
|
||||
$pathExpression = new PathExpression(
|
||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION,
|
||||
$parentName,
|
||||
$rootAlias,
|
||||
$identifier
|
||||
);
|
||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||
|
@ -71,39 +71,23 @@ class WhereInWalker extends TreeWalkerAdapter
|
||||
*/
|
||||
public function walkSelectStatement(SelectStatement $AST)
|
||||
{
|
||||
$rootComponents = array();
|
||||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
|
||||
$isParent = array_key_exists('parent', $qComp)
|
||||
&& $qComp['parent'] === null
|
||||
&& $qComp['nestingLevel'] == 0
|
||||
;
|
||||
if ($isParent) {
|
||||
foreach($AST->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) {
|
||||
$isRoot = $identificationVariableDeclaration->rangeVariableDeclaration
|
||||
&& $identificationVariableDeclaration->rangeVariableDeclaration->aliasIdentificationVariable == $dqlAlias
|
||||
&& $identificationVariableDeclaration->rangeVariableDeclaration->isRoot
|
||||
;
|
||||
if ($isRoot) {
|
||||
$rootComponents[] = array($dqlAlias => $qComp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($rootComponents) > 1) {
|
||||
$queryComponents = $this->_getQueryComponents();
|
||||
// Get the root entity and alias from the AST fromClause
|
||||
$from = $AST->fromClause->identificationVariableDeclarations;
|
||||
if (count($from) > 1) {
|
||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||
}
|
||||
$root = reset($rootComponents);
|
||||
$parentName = key($root);
|
||||
$parent = current($root);
|
||||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName();
|
||||
|
||||
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
|
||||
$rootClass = $queryComponents[$rootAlias]['metadata'];
|
||||
$identifierFieldName = $rootClass->getSingleIdentifierFieldName();
|
||||
|
||||
$pathType = PathExpression::TYPE_STATE_FIELD;
|
||||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) {
|
||||
if (isset($rootClass->associationMappings[$identifierFieldName])) {
|
||||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
|
||||
}
|
||||
|
||||
$pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName, $identifierFieldName);
|
||||
$pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias, $identifierFieldName);
|
||||
$pathExpression->type = $pathType;
|
||||
|
||||
$count = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT);
|
||||
|
Loading…
Reference in New Issue
Block a user