Doctrine DQL Invalid parameter number: the number of related variables does not match the number of tokens

I get the error Invalid parameter number: number of bound variables does not match number of tokens for this request.

I really see no problem, no ideas?

 public function getByPartial($q, Company $company) { $query = $this->createQueryBuilder('u') ->join('u.company',':company') ->where('u.firstName LIKE :q') ->orWhere('u.lastName LIKE :q') ->setParameters(array('company' => $company, 'q' => '%'.$q.'%')) ->getQuery(); return $query->getResult(); } 
+4
source share
2 answers

company cannot be a parameter, you just need to specify an alias, for example:

 public function getByPartial($q, Company $company) { $query = $this->createQueryBuilder('u') ->addSelect('c') ->join('u.company','c') ->where('u.firstName LIKE :q OR u.lastName LIKE :q') ->andWhere('c.id = :companyId') ->setParameters(array('companyId' => $company->getId(), 'q' => '%'.$q.'%')) ->getQuery(); return $query->getResult(); } 
+2
source

You need to pass the exact number of parameters.

 public function getByPartial($q, Company $company) { $query = $this->createQueryBuilder('u') ->join('u.company','c') ->where('u.firstName LIKE :q1 OR u.lastName LIKE :q2') ->andWhere('c.id = :company_id') ->setParameters(array('company_id' => $company->getId(), 'q1' => '%'.$q.'%', 'q2' => '%'.$q.'%')) ->getQuery(); return $query->getResult(); } 

EDITED The connection does not accept any object parameters. Documentation

+1
source

Source: https://habr.com/ru/post/1488448/


All Articles