Q:

doctrine how to use the clause: IN within findOneBy

I am working in a project in Symfony2 and i Have an Entity Called File and what i am trying to do is get one File from the database with some criteria but the most important criteria is that the file should not match with given array of Ids and without implementing a method in the file Repository
$Ids = (1,2,3,4,5);
$file = $repoFile->findOneBy(array(
      'id'=> $Ids,    // the Id should not match with the array $Ids
      'deleted' => NULL,
      'isMain' => 1
  ));

how can i tell doctrine that the file should not match with the array: $Ids
and i prefer to do it directly in my class without having to implement a method in the file Repository

A:

You can use createQueryBuilder for NOT IN() clause
$result= $repoFile->createQueryBuilder('r')
    ->select('r')
    ->where('r.id NOT IN (:ids)' )
    ->setParameter( 'ids', $Ids, \Doctrine\DBAL\Connection::PARAM_INT_ARRAY )
    ->andWhere('r.deleted = :deleted')
    ->setParameter('deleted',NULL)
    ->andWhere('r.isMain= :isMain')
    ->setParameter('isMain',1)
    ->getQuery()->getResult();

