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
This commit is contained in:
parent
514e63f26f
commit
2009f88109
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue