Doctrine 2 - 外连接查询 [英] Doctrine 2 - Outer join query
本文介绍了Doctrine 2 - 外连接查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在SonataAdminBundle / SonataUserBundle的上下文中,我使用查询构建器向列表查询添加静态过滤器:
In the context of the SonataAdminBundle / SonataUserBundle, I'm using the query builder to add static filters to the "list" query :
使用此查询,我只收集Juge组中的用户,查询工作正常:
With this query, I get only users in the group "Juge", the query works well :
$query
->leftJoin( $query->getRootAlias().'.groups', 'g')
->andWhere( 'g.name = :group_name' )
->setParameter('group_name', 'Juge');
在另一个Admin类中,我想做这个查询的对面:获取不在Juge组中的用户。我该怎么执行这个?在doctrine 2中没有outerJoin函数对吗?
In an other Admin class, i want to do the oposite of this query : get the users who ARE NOT in the "Juge" group. How can I perform this? There is not outerJoin function in doctrine 2 right?
推荐答案
我想你想做
$query
->leftJoin( $query->getRootAlias().'.groups', 'g',
Expr\Join::WITH, 'g.name = :group_name')
->where('g.name IS NULL')
->setParameter('group_name', 'Juge');
其中 Expr
是 Doctrine\ORM\Query\Expr
。
这篇关于Doctrine 2 - 外连接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文