我如何在有或没有 DQL 的一对一关系中部分水化对象而没有冗余结果?

How do i partially hydrate an object without redundant results in a one-to-one relationship with or without DQL?

我正在尝试从我的 DB 中获取基本数据以将其显示到滑块中,我不想出于优化目的获取所有数据,所以我在我的 Entity Repository 中做了一个简单的方法来处理这个......但是当我 运行 波纹管方法时,我会得到像 document 这样的冗余结果* 图片

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();
}

例如如果我有 10 个文档,并且由于某些原因 17 张图片,我将总共有 170 个结果 ,如果我将最大结果设置为 5,则所有结果将是 第一个包含 5 张不同图像的文档(图像 1、图像 2、图像 3 等...直到图像 17 ).

那么,我如何在有或没有 DQL 的情况下,在 一对一关系 中部分水合对象而不产生冗余结果?

WITH 条件丢失,以下功能支付账单:

public function getLastGuidesSamples()
{
    return $this->_em->createQuery("
        SELECT
            document.slug,
            document.title,
            document.description,
            document.addingDate,
            document.addingAuthor,
            image.source,
            image.alternative,
            image.width,
            image.height
        FROM AppBundle:Document document
        JOIN AppBundle:Image image
        WITH image.id = document.id
        WHERE document.type = 3
        AND document.isPublished = true
        ORDER BY document.addingDate
    ")->setMaxResults(5)->getResult();
}