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"组中的用户.我该怎么做?学说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',
ExprJoin::WITH, 'g.name = :group_name')
->where('g.name IS NULL')
->setParameter('group_name', 'Juge');
其中 Expr
是 DoctrineORMQueryExpr
.
这篇关于Doctrine 2 - 外连接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文