这段代码不起作用。有人可以帮助我吗?代码为:
class ResultRepository extends EntityRepository
{
public function findAllByUserResultVote($id_vote)
{
$query = $this->createQueryBuilder('r')
//associating tables...
->leftJoin('r.user' , 'u')
->leftJoin('r.answer' , 'a')
->leftJoin('r.vote' , 'v')
//Where idVote (Table result) == id (Table vote)
->where('r.idVote = :idVote')
->setParameter('idVote', $id_vote)
->getQuery();
return $query->getResult();
}
}
我有一个实体用户、答案、投票、结果。
我有4张桌子:用户: id(主)、名称、...
投票:id(主要),问题,...
答:id(主要),idVote,答案...
结果: id (primary), idUser (id table user), idVote (id table vote), idAnswer (id table answer), ...
-----编辑----
感谢您的回答,但这不是我所做的。
结果也是一个表。这只包含id,我需要返回例如:
而不是:1、6、5、3
这: 1, u.name, v.问题, a.答案
public function findAllByUserResultVote($idVote)
{
$queryBuilder = $this->createQueryBuilder('r')
// From your question, it looks like you only want ids
->select('r.id, u.name, v.question, a.answer')
// join with Vote Entity
->leftJoin('r.vote' , 'v')
// join with User Entity
->leftJoin('r.user' , 'u')
// join with Answer Entity
->leftJoin('r.answer' , 'a')
// where id is same as $idVote
->andWhere('v.id = :id_vote')
->setParameter('id_vote', $idVote);
return $queryBuilder
->getQuery()
->getResult();
}