pass array of conditions to doctrine expr()-gt;orx() method(将条件数组传递给教义 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() 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将条件数组传递给教义 expr()->orx() 方法


- 从 PHP 中的输入表单获取日期 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01