CreateQueryBuilder to find a string in an array?

287 Views Asked by At

I want to find if a $work (string) exist in Works (array), how can I write the request?

public function findByProject($project, $work)
{
    return $this->createQueryBuilder('p')
        ->andWhere('p.project_type = :project')
        ->andWhere('p.works = :work')
        ->setParameter('project', $project)
        ->setParameter('work', $work)
        ->orderBy('p.id', 'ASC')
        //->setMaxResults(10)
        ->getQuery()
        ->getResult()
    ;
}
1

There are 1 best solutions below

0
rzp789 On

public function findByProject($project, $work)

{
    return $this->createQueryBuilder('p')
        ->andWhere('p.project_type = :project')
        ->andWhere('p.works LIKE :work')
        ->setParameter('project', $project)
        ->setParameter('work', '%'.$work.'%')
        ->orderBy('p.id', 'ASC')
        //->setMaxResults(10)
        ->getQuery()
        ->getResult()
    ;
}