0

I'm setting up an advanced search for a jobboard and I need to find resumes by contract, knowing that a resume can have multiple contracts.

I have a form where you can choose which type of contract you are looking for (It's a ChoiceType::class with multiple => true)

In my repository :

public function findByContract(array $contract)
{
    return $this->createQueryBuilder('r')
        ->andWhere('r.contract = :con')
        ->setParameter('con', array($contract))
        ->getQuery()
        ->getResult()
    ;
}

In my controller :

public function index(Request $request, ResumeRepository $resumeRepository)
{
    $formSearch = $this->createForm(ResumeSearchFormType::class);
    $formSearch->handleRequest($request);

    if ($formSearch->isSubmitted() && $formSearch->isValid()) {
        $data = $formSearch->getData();

        $r = $resumeRepository->findByContract($data->getContract());
        var_dump($r); die;

This var_dump() returns an empty array.

I don't know how to set multiple parameters for the same key

BanjoSf4
  • 149
  • 1
  • 1
  • 13

2 Answers2

1

Use IN condition:

public function findByContract(array $contract)
{
    return $this->createQueryBuilder('r')
        ->andWhere('r.contract IN (:contracts)')
        ->setParameter('contracts', $contract)
        ->getQuery()
        ->getResult()
    ;
}
marv255
  • 808
  • 6
  • 19
0

In my table resume in phpMyAdmin the column contract look like that :

enter image description here

And in the profiler, the runnable query is :

SELECT r0_.id AS id_0, r0_.city AS city_1, r0_.postal_code AS postal_code_2, r0_.salary AS salary_3, r0_.contract AS contract_4, r0_.experience AS experience_5, r0_.training AS training_6, r0_.motivations AS motivations_7, r0_.ext AS ext_8, r0_.name AS name_9 FROM resume r0_ WHERE r0_.contract IN ('CDI', 'CDD');

So there are many resumes where r.contract == CDD or r.contract == CDI, but the query still return an empty array

Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
BanjoSf4
  • 149
  • 1
  • 1
  • 13