Doctrine orm 如何在Doctrine 2.0的DQL中使用in语句

Doctrine orm 如何在Doctrine 2.0的DQL中使用in语句,doctrine-orm,Doctrine Orm,我有以下使用IN语句的查询 $ids = array(1,2,3); $query = 'select o from Organisation o where o.id in (:ids)'; $this->_entityManager->createQuery($query) ->setParameter('ids', implode(', ', $ids)) 条令没有返回任何结果,我认为这是因为条令对传递的参数$ids的转换出错,该参数是一个数组

我有以下使用IN语句的查询

$ids = array(1,2,3);
$query = 'select o from Organisation o where o.id in (:ids)';
$this->_entityManager->createQuery($query)
            ->setParameter('ids', implode(', ', $ids))
条令没有返回任何结果,我认为这是因为条令对传递的参数
$ids
的转换出错,该参数是一个数组


如何使其工作?

尝试将数组本身传递给
->setParameter(…)
而不是将其内插到字符串中。

我使用了这个(setParameter似乎对我不起作用):


我也在使用$query->expr()->IN()结构处理IN语句

尝试:

我认为在in()部分中围绕参数的简单引号是必要的…

我解决了这个问题:

$con = $this->getEntityManager();
$query = $con->createQuery("SELECT cl
                            FROM BackendBundle:classifieds cl 
                            INNER JOIN BackendBundle:locations lo WITH cl.locationId = lo.id
                            INNER JOIN BackendBundle:municipality mu WITH lo.municipalId = mu.id
                            WHERE cl.verified = false AND mu.id = ".$munId." AND cl.locationId NOT IN (:ids) ");
$query->setParameters(array('ids' => $locsIds));
return $query->getResult();

谢谢Jeremy,我也遇到了同样的问题,
->setParameter('ids',$ids)
确实有效谢谢,这正是我需要的如果你需要多个参数:$query->setParameters(array('ids'=>$locsIds,$munIds'=>$munIds));查询将如下所示:。。。。。其中cl.locationId不在(:ids)中,mu.id不在(:munIds)
$em->createQuery(“SELECT users FROM Entities\User users WHERE users.id IN (':ids')”)
->setParameters(array(‘ids’ => $ids));
$con = $this->getEntityManager();
$query = $con->createQuery("SELECT cl
                            FROM BackendBundle:classifieds cl 
                            INNER JOIN BackendBundle:locations lo WITH cl.locationId = lo.id
                            INNER JOIN BackendBundle:municipality mu WITH lo.municipalId = mu.id
                            WHERE cl.verified = false AND mu.id = ".$munId." AND cl.locationId NOT IN (:ids) ");
$query->setParameters(array('ids' => $locsIds));
return $query->getResult();