学说:期待Lexer :: T_MEMBER,得到'='

时间:2014-08-07 19:38:14

标签: mysql doctrine-orm

我尝试在存储库中定义一个函数:

    public function getBestResultForDisciplineAndRiegeFromActives(Discipline $discipline, Riege $riege){
    $qb = $this->_em->createQueryBuilder();
    $qb->select('r')
        ->from('Result', 'r')
        ->leftJoin('r.event', 'event')
        ->leftJoin('event.riegen', 'riege')
        ->leftJoin('r.member', 'member')
        ->leftJoin('member.membershipHistories', 'membershipHistory');
    $qb->where("r.discipline = :discipline");
    $qb->andWhere("riege = :riege");
    $qb->andWhere("membershipHistory.riege = :riege");
    $qb->andWhere("member.active = 1");
    $qb->addOrderBy('r.value', $discipline->getSortOrder());
    $qb->addOrderBy('event.startDate', "ASC");
    $qb->setParameter('discipline', $discipline);
    $qb->setParameter('riege', $riege);
    $query = $qb->getQuery();   
    $query->setMaxResults(1);
    $result = $query->getOneOrNullResult();
    return $result;         
}

但是,学说“$ qb-> andWhere”(“member.active = 1”);“

出现以下错误:

( ! ) Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message
 'SELECT r FROM Result r LEFT JOIN r.event event LEFT JOIN event.riegen riege LEFT JOIN r.member member LEFT JOIN member.membershipHistories membershipHistory WHERE r.discipline = :discipline AND riege = :riege AND membershipHistory.riege = :riege AND member.active = '1' ORDER BY r.value ASC, event.startDate ASC' in 
    C:\TV\xampp\htdocs\tvdb_wetten\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php on line 52

( ! ) Doctrine\ORM\Query\QueryException: [Syntax Error] line 0, col 264: Error: Expected Doctrine\ORM\Query\Lexer::T_MEMBER, got '=' in 
  C:\TV\xampp\htdocs\tvdb_wetten\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php on line 52

1 个答案:

答案 0 :(得分:1)

加入别名失败了,现在可以了。

public function getBestResultForDisciplineAndRiegeFromActives(Discipline $discipline, Riege $riege){
    $qb = $this->_em->createQueryBuilder();
    $qb->select('r')
        ->from('Result', 'r')
        ->leftJoin('r.event', 'e')
        ->leftJoin('e.riegen', 'riege')
        ->leftJoin('r.member', 'm')
        ->leftJoin('m.membershipHistories', 'membershipHistory');
    $qb->where("r.discipline = :discipline");
    $qb->andWhere("riege = :riege");
    $qb->andWhere("membershipHistory.riege = :riege");
    $qb->andWhere("m.active = 1");
    $qb->addOrderBy('r.value', $discipline->getSortOrder());
    $qb->addOrderBy('e.startDate', "ASC");
    $qb->setParameter('discipline', $discipline);
    $qb->setParameter('riege', $riege);
    $query = $qb->getQuery();   
    $query->setMaxResults(1);
    $result = $query->getOneOrNullResult();
    return $result;         
}