duanji7182 2017-07-13 09:49
浏览 59
已采纳

使用querybuilder在另一个内部构建查询?

I got 2 tables User and Group; each object Group got an array members[] that points to some instances of User.

I need to build this same query with QueryBuilder :

SELECT (users instances) FROM User
WHERE (users instances) IN (SELECT Group.members from Group WHERE group.id = $someId)

How can I achieve that?

  • 写回答

2条回答 默认 最新

  • duan0802 2017-07-13 10:14
    关注

    You have to make 2 querybuilders:

    $qb2 = $this->em->createQueryBuilder('group')
                ->select('group.members')
                ->where('group.id = $someId');
    
    $qb = $this->em->createQueryBuilder('user')
               ->select(user instances)
               -where($qb->expr()->in('user instances', $qb2->getDQL());
    

    it will give you the idea how it works. Of course you have to adjust this code to yours.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 想写一个文件管理器,加载全部子文件夹后,要一级一级返回
  • ¥15 华为超融合部署环境下RedHat虚拟机分区扩容问题
  • ¥15 哪位能做百度地图导航触点播报?
  • ¥15 请问GPT语言模型怎么训练?
  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?