与查询存在主义的Symfony2(Query with EXISTS for Doctrine Sy

2019-06-23 10:13发布

我怎样才能实现与查询生成器下面的查询?

SELECT * 
FROM t 
WHERE t.status = 1
    OR EXISTS(SELECT * 
              FROM r 
              WHERE r.t_id = t.id 
                  AND r.status = 1
             )

不存在检查的部分很容易,但有实施办法EXISTS

Answer 1:

您可能需要使用两个查询生成器:

$queryBuilder->expr()->exists($subQueryBuilder->getDql());

或者直接使用DQL:

$queryBuilder->expr()->exists('SELECT * 
    FROM r 
    WHERE r.t_id = t.id 
    AND r.status = 1'
);

你会发现在这个文档中更多的例子: http://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/query-builder.html



文章来源: Query with EXISTS for Doctrine Symfony2