0

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?

Shawn
  • 10,931
  • 18
  • 81
  • 126

1 Answers1

2

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.

Gedrox
  • 3,592
  • 1
  • 21
  • 29