我做了一个Doctrine查询构建器查询,我有这个错误:
Too few parameters : The query defines 3 parameters but you only bound 2.
我查看了查询并尝试了一些重构,但我无法找到代码错误的地方。
查询:
$query = $this->_em->createQueryBuilder();
$query->select('m')
->from(Matiere::class, 'm')
->join('m.ues', 'ue')
->andWhere($query->expr()->eq('ue.semester', ':semestre'))
->setParameter('semestre', $semestre);
if (count($UEs) === 1) {
$query->andWhere($query->expr()->neq('ue.id', ':ueSpe'))
->setParameter('ueSpe', $UEs);
}
else {
$ueM = $UEs[0];
$ueP = $UEs[1];
$query->andWhere($query->expr()->neq('ue.id', ':ueM'))
->andWhere($query->expr()->neq('ue.id', ':ueP'))
->setParameters(['ueM' => $ueM, 'ueP' => $ueP]);
}
return $query->getQuery()->getResult();
$query = $this->_em->createQueryBuilder();
$query->select('m')
->from(Matiere::class, 'm')
->join('m.ues', 'ue')
->andWhere($query->expr()->eq('ue.semester', ':semestre'))
->setParameter('semestre', $semestre);
if (count($UEs) === 1) {
$query->andWhere($query->expr()->neq('ue.id', ':ueSpe'))
->setParameter('ueSpe', $UEs);
}
else {
$parameters[] = $UEs[0];
$parameters[] = $UEs[1];
$query->andWhere($qb->expr()->notIn('ue.id', ':parameters'))
->setParameter('parameters' => $parameters);
}
return $query->getQuery()->getResult();