postgresql - 教义查询构建器,可空字段的 where 语句
问题描述
当 2 个字段可以为空时,我需要创建查询。
询问:
$qb = $this->entityManager->createQueryBuilder();
$qb->select('t')
->from('Table', 't')
->where('t.name = :name')
->andWhere('t = :country')
->andWhere('t = :language')
->setParameters([
'name' => $info->getName(),
'country' => $info->getCountry(),
'language' => $info->getLanguage()
]);
$result = $qb->getQuery()->getOneOrNullResult();
在所有字段不为空的情况下一切正常,但在我的情况下,country
可以language
为空,并且学说将其转换为查询,例如where country = null
which is not working 并且我没有得到任何结果,因为它应该是where country is null
.
所以我的问题是有一种方法可以处理它并自动转换is null
为提供的参数为空时,还是我需要使用 phpif
语句自行检查?如果我应该自己检查它,这很烦人且容易出错,因为您需要始终知道哪些字段可以为空,并对每个可以为空的字段进行此检查。
仅供参考:我正在使用 Postgres
解决方案
推荐阅读
- excel - 这个 vba 代码有什么问题?设置 SourceRng = SourceWS.Range(Cells(1, 6), Cells(650, 11))
- javascript - 移动设备上的 window.location.replace() 更改为默认(不同)浏览器
- azure-web-app-service - 部署后操作中应用服务 web.config 的路径
- git - 偶然从主人那里拉出来后,我按下了 ctrl+z 和
- postgresql - Debezium Postgres Kafka 没有创建主题
- imagemagick - 为什么 ImageMagick 会创建多页文件?
- python - 有没有一种方法可以加快使用 JAX 索引向量的速度?
- gitlab-ci - Gitlab Pipeline 显示错误状态
- node.js - nodejs node-libcurl HTTP授权-承载身份验证令牌的问题
- css - 使用 UIKit 浮动表单的输入标签