问题
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);
I was thinking of something like this:
$entityManager->getRepository($entity)->findBy(array('ID' => array('NOT IN' => array(1, 2, 3))));
... How far am I?
回答1:
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();
Passing arrays as parameters is supported since Doctrine version 2.1.
来源:https://stackoverflow.com/questions/13199035/how-can-i-fetch-every-row-where-column-is-not-in-array-of-values-with-doctrine