Как читать массив DC2Type с доктриной и Symfony - PullRequest
0 голосов
/ 20 июня 2019

Я настраиваю расширенный поиск доски объявлений, и мне нужно найти резюме по контракту, зная, что резюме может иметь несколько контрактов.

У меня есть форма, в которой вы можете выбрать, какой тип контрактавы ищете (это ChoiceType :: class с множественным числом => true)

В моей таблице мой контракт с колоннами:

enter image description here

В моем Entity Resume:

/**
 * @ORM\Column(type="array", nullable=true)
 */
private $contract = [];

public function getContract(): ?array
{
    return $this->contract;
}

public function setContract(?array $contract): self
{
    $this->contract = $contract;

    return $this;
}

В моем репозитории:

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

В моем контроллере:

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

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

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

Этот var_dump () возвращает пустой массив.

Не знаю, как мне найти резюме по контракту

...