如何使用Doctrine提取列不在(值数组)中的每一行? [英] How can I fetch every row where column is not in (array of values) with Doctrine?

查看:70
本文介绍了如何使用Doctrine提取列不在(值数组)中的每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试完成类似于以下SQL的操作,但是使用的是Doctrine API。

I'm trying to accomplish something similar to the following SQL, but using the Doctrine API.

SELECT * FROM table_name WHERE column_name NOT IN (1, 2, 3);

我在想这样的事情:

$entityManager->getRepository($entity)->findBy(array('ID' => array('NOT IN' => array(1, 2, 3))));

...我走了多远?

推荐答案

您可以使用DQL进行此操作:

You can do this with a DQL:

$result = $entityManager->createQuery("SELECT e FROM $entity e 
        WHERE e.ID NOT IN (:ids)")
    ->setParameter('ids', array(1, 2, 3), \Doctrine\DBAL\Connection::PARAM_INT_ARRAY)
    ->getResult();

自Doctrine 2.1版开始,支持将数组作为参数传递。

Passing arrays as parameters is supported since Doctrine version 2.1.

这篇关于如何使用Doctrine提取列不在(值数组)中的每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆