将条件数组传递给doctrine expr() - > orx()方法 [英] pass array of conditions to doctrine expr()->orx() method

查看:238
本文介绍了将条件数组传递给doctrine expr() - > orx()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 QueryBuilder 构造DQL,这样

I need to construct DQL with a QueryBuilder like this

[QUERY]... AND WHERE e.type = x OR e.type = Y OR e.type = N [...]

我在数组中有类型我如何将此数组传递给我的查询构建器?

I have types in array How can I pass this array to my query builder?

$qb->andWhere($qb->expr()->orx(CONDITIONS));

类型列表将是动态的,调用 $ qb-> andWhere 每个foreach类型循环将只会增加AND WHERE没有更多的OR。
我可以存储多个 orx 表达式,然后将其添加到?任何想法如何解决这个,可能是常见的问题?

List of types will be dynamic, calling $qb->andWhere on each foreach types loop will make only more AND WHERE's no more ORs.
Can I store multiply orx expressions and then add it to andWhere? Any idea how to solve this, probably, common problem?

推荐答案

我知道tommarow会是一个更美好的一天。
解决方案很简单。您可以使用这样的OR表达式数组

I knew that tommarow gonna be a better day. The solution is simple. Your can make array of OR expressions like so

$ors[] = $qb->expr()->orx('e.type = '.$qb->expr()->literal($value));

然后将它添加到andWhere()/ Where()方法的查询构建器通过连接方法像这样:

And then just add it to andWhere()/Where() method of the query builder via join method like so:

$qb->andWhere(join(' OR ', $ors));

这篇关于将条件数组传递给doctrine expr() - > orx()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆