【发布时间】:2014-07-24 05:19:43
【问题描述】:
您好,我有一个具有两个主键的实体。
class UsefulnessEvaluation
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="App\EvaluationBundle\Entity\Evaluation", cascade={"persist","remove"})
*/
private $evaluation;
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="App\UserBundle\Entity\User", cascade={"persist","remove"})
*/
private $user;
/**
*
* @ORM\Column(type="string", nullable=false)
*/
private $type;
/**
* @ORM\Column(type="datetime", nullable=false)
*/
private $createdAt;
//etc
}
我想在存储库中,计算一个评估的数量:
class UsefulnessEvaluationRepository extends EntityRepository
{
public function countEvaluationLikes($evaluation_id)
{
$query = $this->getEntityManager()->createQuery(
'SELECT count(p.evaluation) as nbre
FROM AppEvaluationBundle:UsefulnessEvaluation p
WHERE p.evaluation = :id
)->setParameter('id', $evaluation_id);
return $query->getSingleScalarResult();
}
}
这是错误:
将具有复合主键的实体绑定到查询不是 支持的。您应该将参数拆分为显式字段和 分别绑定。
【问题讨论】:
标签: symfony doctrine-orm repository