2016-03-16 121 views
0

嗨,我有以下連接查詢。語法錯誤Symfony2查詢

return $this->getEntityManager() 
     ->createQuery(
      "SELECT t1.taskId,t1.title,t1.dueDate,t1.modified,cb.forename,cb.surname,up.profilePhotoPath, 
      (SELECT tp.metaData,tp.content FROM AppBundle:J1TaskPost tp order by tp.created DESC) AS taskPost 
      FROM AppBundle:J1Task as t1 
      JOIN t1.assignees As ta 
      JOIN t1.createdBy As cb 
      JOIN AppBundle:J1UserProfile as up WITH t1.createdBy = up.user 
      WHERE t1.deleted IS NULL and t1.status = false and ta.userid=$userId group by t1.taskId order by tp.created desc" 
     )->getResult(); 

它拋出以下錯誤:

Syntax Error] line 0, col 130: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got ','. 

我無法找出什麼在上面的查詢失蹤。

回答

0

的問題是在這條線:

"SELECT t1.taskId,t1.title,t1.dueDate,t1.modified,cb.forename,cb.surname,up.profilePhotoPath, 
(SELECT tp.metaData,tp.content FROM AppBundle:J1TaskPost tp order by tp.created DESC) AS taskPost 

您需要選擇內taskPost的項目,但你在這裏所做的是定義表來代替。你可以做的是:

SELECT t1.taskId,t1.title,t1.dueDate,t1.modified,cb.forename,cb.surname,up.profilePhotoPath, taskPost.metaData, taskPost.content FROM 
(SELECT tp.metaData,tp.content FROM AppBundle:J1TaskPost tp order by tp.created DESC) AS taskPost, 
... 
+0

嗨Aculay我都試過,但得到的另一個錯誤: 返回$這個 - > getEntityManager() - >的createQuery( 「選擇t1.taskId,t1.title,T1。 dueDate,t1.modified,cb.forename,cb.surname,up.profilePhotoPath,taskPost.metaData,taskPost.content FROM (SELECT tp.metaData,tp.content FROM AppBundle:J1TaskPost tp order by tp.created DESC)AS taskPost [語義錯誤] line 0,col 134 near'(SELECT tp.metaData,tp.content':Error:Class'('is not defined。 –