我有這個查詢與子查詢:錯誤與doctrine2查詢生成器子查詢
$query = $this->getEntityManager()->createQueryBuilder();
$subquery = $query;
$subquery
->select('f.following')
->from('ApiBundle:Follow', 'f')
->where('f.follower = :follower_id')
->setParameter('follower_id', $id)
;
$query
->select('c')
->from('ApiBundle:Chef', 'c')
->where('c.id <> :id')
->setParameter('id', $id)
;
$query
->andWhere(
$query->expr()->notIn('c.id', $subquery->getDQL())
);
return $query->getQuery()->getResult();
而且我得到這個錯誤:
[Semantical Error] line 0, col 116 near 'f, ApiBundle:Chef': Error: 'f' is already defined.
我無法找到錯誤的原因,別名f只定義一次。有什麼建議麼?
非常感謝,但是現在的錯誤是:[語義錯誤]第0行,第74行'FROM FROM'後面:錯誤:無效PathExpression。必須是StateFieldPathExpression。 – m4t1t0
@ m4t1t0可以幫助:http://stackoverflow.com/questions/14216470/symfony2-and-doctrine-error-invalid-pathexpression-must-be-a-statefieldpathe – cheesemacfly
是的,它可以幫助我,謝謝! – m4t1t0