Skip to content

Commit

Permalink
doctrine#7820 use PersisterHelper to figure out identifier types
Browse files Browse the repository at this point in the history
This logic was pre-existing, but I forgot about it while writing
doctrine#7820, therefore it was re-implemented inside this unit of
code. Now we just use the `PersisterHelper`, which does all
the nice and shiny identifier type discovery operations we need.
  • Loading branch information
Ocramius committed Sep 20, 2019
1 parent 681ff32 commit 0de1731
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@

namespace Doctrine\ORM\Tools\Pagination;

use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query\AST\ArithmeticExpression;
use Doctrine\ORM\Query\AST\SimpleArithmeticExpression;
use Doctrine\ORM\Query\TreeWalkerAdapter;
use Doctrine\ORM\Query\AST\SelectStatement;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\AST\InExpression;
use Doctrine\ORM\Query\AST\NullComparisonExpression;
use Doctrine\ORM\Query\AST\InputParameter;
use Doctrine\ORM\Query\AST\ConditionalPrimary;
use Doctrine\ORM\Query\AST\ConditionalTerm;
use Doctrine\ORM\Query\AST\ConditionalExpression;
use Doctrine\ORM\Query\AST\ConditionalFactor;
use Doctrine\ORM\Query\AST\ConditionalPrimary;
use Doctrine\ORM\Query\AST\ConditionalTerm;
use Doctrine\ORM\Query\AST\InExpression;
use Doctrine\ORM\Query\AST\InputParameter;
use Doctrine\ORM\Query\AST\NullComparisonExpression;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\AST\SelectStatement;
use Doctrine\ORM\Query\AST\SimpleArithmeticExpression;
use Doctrine\ORM\Query\AST\WhereClause;
use Doctrine\ORM\Query\TreeWalkerAdapter;
use Doctrine\ORM\Utility\PersisterHelper;
use function array_map;
use function assert;
use function is_array;
Expand Down Expand Up @@ -87,7 +88,7 @@ public function walkSelectStatement(SelectStatement $AST)

$fromRoot = reset($from);
$rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable;
/** @var ClassMetadataInfo $rootClass */
/** @var ClassMetadata $rootClass */
$rootClass = $queryComponents[$rootAlias]['metadata'];
$identifierFieldName = $rootClass->getSingleIdentifierFieldName();

Expand All @@ -109,7 +110,14 @@ public function walkSelectStatement(SelectStatement $AST)
$expression = new InExpression($arithmeticExpression);
$expression->literals[] = new InputParameter(":" . self::PAGINATOR_ID_ALIAS);

$this->convertWhereInIdentifiersToDatabaseValue($this->getTypeOfSingleIdentifierColumn($rootClass));
$this->convertWhereInIdentifiersToDatabaseValue(
PersisterHelper::getTypeOfField(
$identifierFieldName,
$rootClass,
$this->_getQuery()
->getEntityManager()
)[0]
);
} else {
$expression = new NullComparisonExpression($pathExpression);
$expression->not = false;
Expand Down Expand Up @@ -173,19 +181,4 @@ private function convertWhereInIdentifiersToDatabaseValue(string $type) : void
return $connection->convertToDatabaseValue($id, $type);
}, $identifiers));
}

private function getTypeOfSingleIdentifierColumn(ClassMetadataInfo $class) : string
{
$identifierField = $class->getSingleIdentifierFieldName();

if ($class->hasField($identifierField)) {
return (string) $class->getTypeOfField($identifierField);
}

return $this->getTypeOfSingleIdentifierColumn(
$this->_getQuery()
->getEntityManager()
->getClassMetadata($class->getAssociationTargetClass($identifierField))
);
}
}

0 comments on commit 0de1731

Please sign in to comment.