douhuan6305 2019-05-24 09:30
浏览 80

我无法正确使用Doctrine Expr

I want to change this query to doctrine but I couldn't.

select * from table1
left join table2 on table2.hotel_id = table1.id
left join table3 on table2.table3_id = table3.id
left join (

  select COUNT(h.hotel_id) as count, h.hotel_id as hotel from table2 h
  where h.id in (1, 3) ) t1 on t1.hotel = table1.id

where table3.id in (11, 12, 13, 14, 15, 16)
and t1.count = 2

Note: t1.count is array length.

$qb = $this->getEntityManager()->createQueryBuilder()
                ->addSelect('table1')
                ->addSelect('table2')
                ->addSelect('table3')

                ->from(\App\Entity\...::class, 'table1')
                ->leftJoin('table1.table2', 'table2', 'with', 'table2.isActive = true')
                ->leftJoin('table2.table3', 'table3');

    $qb
      ->andWhere(
          $qb->expr()->andX(
              $qb->expr()->in('table3.id', ':prop')   
          )
      )->setParameter(':prop', $props);

This is my selection query but i dont use nested query. I want to use Doctrine Expr.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程