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

查看:19
本文介绍了将条件数组传递给教义 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));

类型列表将是动态的,在每个 foreach 类型循环上调用 $qb->andWhere 只会产生更多 AND WHERE 不再有 OR.
我可以存储乘法 orx 表达式,然后将其添加到 andWhere 中吗?知道如何解决这个可能是常见问题吗?

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?

推荐答案

我知道明天会更好.解决方案很简单.您可以像这样制作 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));

然后通过 join 方法将其添加到查询构建器的 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));

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

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