How to get partial result from doctrine query builder

后端 未结 2 1511
太阳男子
太阳男子 2021-01-06 22:41

I have a product entity in which it has an array as attributes:

     /**
     * @ORM\\OneToMany(targetEntity=\"Shopious\\MainBundle\\Entity\\ProductPicture\"         


        
2条回答
  •  不思量自难忘°
    2021-01-06 23:06

    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')
                ;
    

提交回复
热议问题