如何在 Doctrine 2.0 中的 DQL 中使用 in 语句 [英] How to use the in statement in DQL in Doctrine 2.0
本文介绍了如何在 Doctrine 2.0 中的 DQL 中使用 in 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下使用 IN 语句的查询.
I have the following query that uses an IN statement.
$ids = array(1,2,3);
$query = 'select o from Organisation o where o.id in (:ids)';
$this->_entityManager->createQuery($query)
->setParameter('ids', implode(', ', $ids))
Doctrine 没有返回任何结果,我认为这是因为 Doctrine 对传递的参数 $ids
进行的转换有问题,该参数是一个数组.
Doctrine is not returning any results, I think it is because of something wrong in the conversion that Doctrine does for the passed parameter $ids
which is an array.
如何让它发挥作用?
推荐答案
尝试将数组本身传递给 ->setParameter(...)
而不是将其内爆为字符串.
Try passing the array itself to ->setParameter(...)
instead of imploding it into a string.
这篇关于如何在 Doctrine 2.0 中的 DQL 中使用 in 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文