我想从“Cours”表中获取所有记录,其中由表单提交的$speciality
的值是IN arrayColloction()
由每个返回类别Cours
的单个对象。我使用的下一行有那个结果(但遗憾的是它不工作):可捕获的致命错误:类的对象...不能转换为字符串
public function andWhereSpeciality(QueryBuilder $qb, Speciality $speciality)
{
$qb
->andWhere($qb->expr()->in(':speciality','a.specialities'))
->setParameter('speciality', $speciality) ;
return $qb;
}
类Cours
有ManyToMany
关系就像下面的代码:
/**
* @ORM\ManyToMany(targetEntity="BacUp\GeneralBundle\Entity\Speciality", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Assert\Count(min = 1, minMessage = "You have to choose at least one speciality")
*/
private $specialities;
执行返回以下错误:
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Catchable Fatal Error: Object of class BacUp\GeneralBundle\Entity\Speciality could not be converted to string in C:\wamp\www\Symfony\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Expr.php line 452" at C:\wamp\www\Symfony\vendor\doctrine\orm\lib\Doctrine\ORM\Query\Expr.php line 452
现在我收到以下异常:[code] CRITICAL - 未捕获到PHP异常Symfony \ Component \ Debug \ Exception \ UndefinedMethodException:“尝试在C中的类”Doctrine \ ORM \ Query \ Expr“上调用方法”isMemberOf“ :\ wamp \ www \ Symfony \ src \ BacUp \ GeneralBundle \ Entity \ CoursRepository.php line 84.“在C:\ wamp \ www \ Symfony \ src \ BacUp \ GeneralBundle \ Entity \ CoursRepository.php第84行[/ code] – 2015-01-10 13:54:54
现在,它能正常工作......谢谢。 – 2015-01-10 14:15:00