Fix order of objects returned by the doctrine mapper

This commit is contained in:
ornicar 2011-04-25 12:32:05 -07:00
parent d1407950b5
commit de6e25e74b

View file

@ -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;
}
}