将sql转换为doctrine symfony或DQL

时间:2016-05-25 08:16:34

标签: sql symfony doctrine dql

你好我在数据库中有2对多关系并且使用sql查询是可以但是不能将查询mysql转换为dql或querybuilder请帮帮我

SELECT * 
FROM `resturant`
LEFT JOIN `food`
    ON `resturant`.`id` = `food`.`resturant_id` 
WHERE `food`.`name`LIKE "%pizza%" 
GROUP BY `resturant`.`name`

1 个答案:

答案 0 :(得分:0)

假设您的Restaurant实体通过属性Food$foods实体相关联:

$this->createQueryBuilder('restaurant')
    ->leftJoin('restaurant.foods', 'food')
    ->where('food.name LIKE %pizza%')
    ->groupBy('restaurant.name')
    ->getQuery()->getResult();