symfony – ‘不在’查询与原则查询构建器’

我试图重现这个查询:

SELECT * FROM `request_lines`
where request_id not in(
select requestLine_id from `asset_request_lines` where asset_id = 1 
)

在教义查询构建器中,
我停留在request_id不在的位置(select

我目前有:

$linked = $em->createQueryBuilder()
        ->select('rl')
        ->from('MineMyBundle:MineRequestLine', 'rl')
        ->where()
        ->getQuery()
        ->getResult();
您需要使用查询构建器表达式,这意味着您需要访问查询构建器对象。此外,如果提前生成子选择列表,代码更容易写入:

$qb = $em->createQueryBuilder();

$nots = $qb->select('arl')
          ->from('$MineMyBundle:MineAssetRequestLine', 'arl')
          ->where($qb->expr()->eq('arl.asset_id',1))
          ->getQuery()
          ->getResult();

$linked = $qb->select('rl')
             ->from('MineMyBundle:MineRequestLine', 'rl')
             ->where($qb->expr()->notIn('rl.request_id', $nots))
             ->getQuery()
             ->getResult();
http://stackoverflow.com/questions/13957330/where-not-in-query-with-doctrine-query-builder

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:symfony – ‘不在’查询与原则查询构建器’