且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从学说查询生成器中获取部分结果

更新时间:2023-09-18 23:06:52

试试这样,如果是一对多,正常的mySQL行为是返回多条带有冗余产品数据的记录,如果这里发生同样的情况,那么只返回第一条记录就可以了.

PS:假设 ProductPicture 实体有一个您想要获取的 url 属性

Try something like this, if it's a one to many, the normal mySQL behaviour is returning several records with redundant product data, if the same case happens here, then only returning the first record should do the trick.

PS: assuming the ProductPicture entity has a url property that you want to get

$query = $em->createQueryBuilder()->select('p.id, p.name, pictures.url')
            ->from("SiteMainBundle:Product", 'p')
            ->innerJoin('p.category', 'c')
            ->innerJoin('p.shop', 'shop')
            ->innerJoin('p.pictures', 'pictures')
            ;