From 2009f8810911e1999aa8d2966b0c076854258daa Mon Sep 17 00:00:00 2001 From: Peter Mitchell Date: Wed, 19 Mar 2014 08:40:52 -0400 Subject: [PATCH] Make fetchSlice compatible with custom repo method If a user configures query_builder_method for the doctrine provider, and does not alias the root entity to equal Provider::ENTITY_ALIAS then a DQL error will occur during index population. > [Semantical Error] [...] near 'a.id ASC': Error: 'a' is not defined. Provider::countObjects already handles this by dynamically fetching the alias with QueryBuilder::getRootAliases, and Provider::fetchSlice should be doing the same. nb. "Provider" refers to FOS\ElasticaBundle\Doctrine\ORM\Provider --- Doctrine/ORM/Provider.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doctrine/ORM/Provider.php b/Doctrine/ORM/Provider.php index 3549550..5d0164f 100644 --- a/Doctrine/ORM/Provider.php +++ b/Doctrine/ORM/Provider.php @@ -9,7 +9,7 @@ use FOS\ElasticaBundle\Exception\InvalidArgumentTypeException; class Provider extends AbstractProvider { const ENTITY_ALIAS = 'a'; - + /** * @see FOS\ElasticaBundle\Doctrine\AbstractProvider::countObjects() */ @@ -50,12 +50,13 @@ class Provider extends AbstractProvider */ $orderBy = $queryBuilder->getDQLPart('orderBy'); if (empty($orderBy)) { + $rootAliases = $queryBuilder->getRootAliases(); $identifierFieldNames = $this->managerRegistry ->getManagerForClass($this->objectClass) ->getClassMetadata($this->objectClass) ->getIdentifierFieldNames(); foreach ($identifierFieldNames as $fieldName) { - $queryBuilder->addOrderBy(static::ENTITY_ALIAS.'.'.$fieldName); + $queryBuilder->addOrderBy($rootAliases[0].'.'.$fieldName); } }