Fix order of objects returned by the doctrine mapper
This commit is contained in:
parent
d1407950b5
commit
de6e25e74b
|
@ -62,12 +62,21 @@ class DoctrineMapper implements MapperInterface
|
|||
return $elasticaObject->getId();
|
||||
}, $elasticaObjects);
|
||||
|
||||
return $this->objectManager
|
||||
$objects = $this->objectManager
|
||||
->createQueryBuilder($this->objectClass)
|
||||
->field($this->options['identifier'])->in($ids)
|
||||
->hydrate($this->options['hydrate'])
|
||||
->getQuery()
|
||||
->execute()
|
||||
->toArray();
|
||||
|
||||
// sort objects in the order of ids
|
||||
$idPos = array_flip($ids);
|
||||
usort($objects, function($a, $b) use ($idPos)
|
||||
{
|
||||
return $idPos[$a->getId()] > $idPos[$b->getId()];
|
||||
});
|
||||
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue