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');
|
throw new \RuntimeException('Cannot count query that uses a HAVING clause. Use the output walkers for pagination');
|
||||||
}
|
}
|
||||||
|
|
||||||
$rootComponents = array();
|
$queryComponents = $this->_getQueryComponents();
|
||||||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
|
// Get the root entity and alias from the AST fromClause
|
||||||
$isParent = array_key_exists('parent', $qComp)
|
$from = $AST->fromClause->identificationVariableDeclarations;
|
||||||
&& $qComp['parent'] === null
|
if (count($from) > 1) {
|
||||||
&& $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) {
|
|
||||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||||
}
|
}
|
||||||
$root = reset($rootComponents);
|
|
||||||
$parentName = key($root);
|
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
|
||||||
$parent = current($root);
|
$rootClass = $queryComponents[$rootAlias]['metadata'];
|
||||||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName();
|
$identifierFieldName = $rootClass->getSingleIdentifierFieldName();
|
||||||
|
|
||||||
$pathType = PathExpression::TYPE_STATE_FIELD;
|
$pathType = PathExpression::TYPE_STATE_FIELD;
|
||||||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) {
|
if (isset($rootClass->associationMappings[$identifierFieldName])) {
|
||||||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
|
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pathExpression = new PathExpression(
|
$pathExpression = new PathExpression(
|
||||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName,
|
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias,
|
||||||
$identifierFieldName
|
$identifierFieldName
|
||||||
);
|
);
|
||||||
$pathExpression->type = $pathType;
|
$pathExpression->type = $pathType;
|
||||||
|
@ -60,37 +60,34 @@ class LimitSubqueryWalker extends TreeWalkerAdapter
|
|||||||
*/
|
*/
|
||||||
public function walkSelectStatement(SelectStatement $AST)
|
public function walkSelectStatement(SelectStatement $AST)
|
||||||
{
|
{
|
||||||
$parent = null;
|
$queryComponents = $this->_getQueryComponents();
|
||||||
$parentName = null;
|
// 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();
|
$selectExpressions = array();
|
||||||
|
|
||||||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
|
foreach ($queryComponents as $dqlAlias => $qComp) {
|
||||||
// Preserve mixed data in query for ordering.
|
// Preserve mixed data in query for ordering.
|
||||||
if (isset($qComp['resultVariable'])) {
|
if (isset($qComp['resultVariable'])) {
|
||||||
$selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias);
|
$selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
|
|
||||||
$parent = $qComp;
|
|
||||||
$parentName = $dqlAlias;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$identifier = $parent['metadata']->getSingleIdentifierFieldName();
|
$identifier = $rootClass->getSingleIdentifierFieldName();
|
||||||
if (isset($parent['metadata']->associationMappings[$identifier])) {
|
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.");
|
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(
|
$this->_getQuery()->setHint(
|
||||||
self::IDENTIFIER_TYPE,
|
self::IDENTIFIER_TYPE,
|
||||||
Type::getType($parent['metadata']->getTypeOfField($identifier))
|
Type::getType($rootClass->getTypeOfField($identifier))
|
||||||
);
|
);
|
||||||
|
|
||||||
$pathExpression = new PathExpression(
|
$pathExpression = new PathExpression(
|
||||||
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION,
|
PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION,
|
||||||
$parentName,
|
$rootAlias,
|
||||||
$identifier
|
$identifier
|
||||||
);
|
);
|
||||||
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
$pathExpression->type = PathExpression::TYPE_STATE_FIELD;
|
||||||
|
@ -71,39 +71,23 @@ class WhereInWalker extends TreeWalkerAdapter
|
|||||||
*/
|
*/
|
||||||
public function walkSelectStatement(SelectStatement $AST)
|
public function walkSelectStatement(SelectStatement $AST)
|
||||||
{
|
{
|
||||||
$rootComponents = array();
|
$queryComponents = $this->_getQueryComponents();
|
||||||
foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
|
// Get the root entity and alias from the AST fromClause
|
||||||
$isParent = array_key_exists('parent', $qComp)
|
$from = $AST->fromClause->identificationVariableDeclarations;
|
||||||
&& $qComp['parent'] === null
|
if (count($from) > 1) {
|
||||||
&& $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) {
|
|
||||||
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
throw new \RuntimeException("Cannot count query which selects two FROM components, cannot make distinction");
|
||||||
}
|
}
|
||||||
$root = reset($rootComponents);
|
|
||||||
$parentName = key($root);
|
$rootAlias = $from[0]->rangeVariableDeclaration->aliasIdentificationVariable;
|
||||||
$parent = current($root);
|
$rootClass = $queryComponents[$rootAlias]['metadata'];
|
||||||
$identifierFieldName = $parent['metadata']->getSingleIdentifierFieldName();
|
$identifierFieldName = $rootClass->getSingleIdentifierFieldName();
|
||||||
|
|
||||||
$pathType = PathExpression::TYPE_STATE_FIELD;
|
$pathType = PathExpression::TYPE_STATE_FIELD;
|
||||||
if (isset($parent['metadata']->associationMappings[$identifierFieldName])) {
|
if (isset($rootClass->associationMappings[$identifierFieldName])) {
|
||||||
$pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
|
$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;
|
$pathExpression->type = $pathType;
|
||||||
|
|
||||||
$count = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT);
|
$count = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT);
|
||||||
|
Loading…
Reference in New Issue
Block a user