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


- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01