【问题标题】:How can I fetch every row where column is not in (array of values) with Doctrine?如何使用 Doctrine 获取列不在(值数组)中的每一行?
【发布时间】:2012-11-02 16:11:10
【问题描述】:

我正在尝试完成类似于以下 SQL 的操作,但使用 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))));

...我还有多远?

【问题讨论】:

    标签: doctrine doctrine-orm entitymanager


    【解决方案1】:

    您可以使用 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 版开始支持将数组作为参数传递。

    【讨论】:

      猜你喜欢
      • 2017-09-13
      • 2013-12-21
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 2020-11-01
      相关资源
      最近更新 更多