使用 EXISTS 查询 Doctrine Symfony2 [英] Query with EXISTS for Doctrine Symfony2
本文介绍了使用 EXISTS 查询 Doctrine Symfony2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用查询生成器实现以下查询?
How can I implement the following query with Query Builder?
SELECT *
FROM t
WHERE t.status = 1
OR EXISTS(SELECT *
FROM r
WHERE r.t_id = t.id
AND r.status = 1
)
不存在检查的部分很简单,但是有没有办法实现EXISTS
?
The part without exist check is easy, but is there a way to implement the EXISTS
?
推荐答案
您要么需要使用两个查询构建器:
You either need to use two query builders:
$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
You'll find more examples in the docs: http://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/query-builder.html
这篇关于使用 EXISTS 查询 Doctrine Symfony2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文