I'm trying to fetch basic data from my DB to display these into a slider, and i don't want to fetch all the data for optimisation purpose, so i've made a simple method inside my Entity Repository to handle this... but when i run the bellow method, i will have redundant results like document * image
public function getLastGuidesSamples()
{
return $this->_em->createQuery("
SELECT
document.slug,
document.title,
document.description,
image.source,
image.alternative,
image.width,
image.height
FROM AppBundle:Document document
JOIN AppBundle:Image image
WHERE document.type = 3
AND document.isPublished = true
ORDER BY document.addingDate
")->setMaxResults(5)->getResult();
}
e.g. if i have 10 documents, and for some reasons 17 images i will have a total of 170 results, and if i set the maximum results to 5, all the results will be the first document with 5 differents images (image 1, image 2, image 3, etc... until image 17).
So how do i partially hydrate an object without redundant results in a one-to-one relationship with or without DQL?