[英]Doctrine2 QB Sementical error on OneToMany join
我正在嘗試使用Doctrine2 QueryBuilder創建查詢。
$qb = $this->getObjectManager()->createQueryBuilder();
$qb->select( array('n', 't', 'c') )
->from('Application\Entity\Notification', 'n')
->leftJoin('n.notificationType', 't')
->leftJoin('n.course', 'c')
->leftJoin('c.studyCourses', 's');
實體課程中的相關代碼如下:
/**
* @ORM\OneToMany(targetEntity="StudyCourses", mappedBy="Course", cascade={"all"})
*/
protected $studyCourses;
實體StudyCourse中的相關代碼如下:
/**
* @ORM\ManyToOne(targetEntity="Course", inversedBy="studyCourses")
* @ORM\JoinColumn(name="Course", referencedColumnName="Id", nullable=true)
*/
protected $course;
現在,當我嘗試運行查詢時,出現了“”附近的語義錯誤。 我認為打印由Doctrine創建的SQL將為我提供有關此錯誤的更好信息,但實際上它是:
SELECT n0_.Id AS Id0, n0_.Timestamp AS Timestamp1, n0_.TitleHtml AS TitleHtml2, n0_.ContentHtml AS ContentHtml3, n1_.Id AS Id4, n1_.Created AS Created5, n1_.Updated AS Updated6, n1_.Name AS Name7, c2_.Id AS Id8, c2_.Created AS Created9, c2_.Updated AS Updated10, c2_.Name AS Name11, c2_.Description AS Description12, c2_.Code AS Code13, c2_.ObjectId AS ObjectId14, c2_.IsActive AS IsActive15, n0_.NotificationType AS NotificationType16, n0_.User AS User17, n0_.Department AS Department18, n0_.Study AS Study19, n0_.Course AS Course20, n0_.Category AS Category21, c2_.Language AS Language22 FROM Notification n0_ LEFT JOIN NotificationType n1_ ON n0_.NotificationType = n1_.Id LEFT JOIN Course c2_ ON n0_.Course = c2_.Id LEFT JOIN
它在LEFT JOIN之后停止!
我們將不勝感激,因為我真的不知道自己在做什么錯,也不知道如何解決此問題。 我在互聯網上搜索了類似的錯誤,但到目前為止還沒有運氣。
嘗試至少選擇在select數組內在studyCourses表中形成leftJoin所需的列。 首先嘗試獲取所有內容,例如“ select(array('n','t','c','s'))”。 如果您沒有選擇該列,有時會中斷。 如果這行得通,請不要獲取studyCourses表中的所有列,只需選擇select中的相關列即可形成leftJoin,例如's.id'。
希望這可以幫助。
干杯!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.