简体   繁体   English

OneToMany连接上的Doctrine2 QB Sementical错误

[英]Doctrine2 QB Sementical error on OneToMany join

I am trying to create a query using the Doctrine2 QueryBuilder. 我正在尝试使用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');

The relevant code in entity Course looks like: 实体课程中的相关代码如下:

    /**
     * @ORM\OneToMany(targetEntity="StudyCourses", mappedBy="Course", cascade={"all"})
     */
    protected $studyCourses;

The relevant code in entity StudyCourse looks like: 实体StudyCourse中的相​​关代码如下:

    /**
     * @ORM\ManyToOne(targetEntity="Course", inversedBy="studyCourses")
     * @ORM\JoinColumn(name="Course", referencedColumnName="Id", nullable=true)
     */
    protected $course;  

Now, when I try to run my query, I'm getting a semantic error near ''. 现在,当我尝试运行查询时,出现了“”附近的语义错误。 I figured printing the SQL created by Doctrine would give me better information about this error, but in fact it is: 我认为打印由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 

It just stops after the LEFT JOIN! 它在LEFT JOIN之后停止!

Any help would be appreciated, as I really don't know what I'm doing wrong, or how to solve this issue. 我们将不胜感激,因为我真的不知道自己在做什么错,也不知道如何解决此问题。 I searched the internet for similar errors, but no luck so far. 我在互联网上搜索了类似的错误,但到目前为止还没有运气。

Try at least selecting columns which are required to form the leftJoin in studyCourses table, inside select array. 尝试至少选择在select数组内在studyCourses表中形成leftJoin所需的列。 First try and get everything such as "select( array('n', 't', 'c', 's') )". 首先尝试获取所有内容,例如“ select(array('n','t','c','s'))”。 Sometimes it breaks if you haven't selected the column. 如果您没有选择该列,有时会中断。 If this worked, don't take all columns which are inside studyCourses table, just get the relevant column in select in order to form the leftJoin, such as 's.id'. 如果这行得通,请不要获取studyCourses表中的所有列,只需选择select中的相关列即可形成leftJoin,例如's.id'。

Hope this helps. 希望这可以帮助。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM