【发布时间】:2015-03-08 04:59:29
【问题描述】:
我正在尝试从“课程”表中获取所有记录,其中由表单提交的 $speciality 的值在 arrayColloction() 中,该 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
【问题讨论】:
标签: php symfony orm doctrine-orm