开发者

Doctrine 2 and "unknown column in "ON clause"

I am currently working in a project that is using Doctrine 2 with ZF. So far so good. However I have a problem that looks like a bug.

I have written the following code in one of my repository :

$dql = 'SELECT a, s.firstName, s.lastName FROM Model_Application a, Model_Mission m 
        JOIN a.student s WHERE a.mission = m.id AND m.company = :company';

$result = $this->getEntityManager()->createQuery($dql)
                                   ->setParameter('company', $company)
                                   ->getResult();

The following SQL was generated :

SELECT a0_.coverLetter AS coverLett开发者_JS百科er0, [... lot of useless things],
a0_.student_id AS student_id5, a0_.mission_id AS mission_id6
FROM Applications a0_, Missions m2_ INNER JOIN Students s3_
ON a0_.student_id = s3_.id LEFT JOIN Users u1_ ON s3_.id = u1_.id
WHERE a0_.mission_id = m2_.id AND m2_.company_id = ?

However, I always get a "Unknown column a0_.student_id in ON clause" BUT the student_id column really exists in the Applications table.

I googled a little and found this link http://www.oscommerce-fr.info/faq/qa_info.php?qID=198 (sorry it's in French) that says that after MySQL 5.0.12, the parser has changed and that you have to add parenthesis when you have several FROM clauses (which is my case).

If I rewrite the SQL code by changing : FROM Applications a0_, Missions m2_

to :

FROM (Applications a0_, Missions m2_)

It works ! HOWEVER I don't know how to add those parenthesis in DQL code (I tried, but it fails).

So maybe it's a bug and Doctrine 2 should insert parenthesis whenever you have more than one FROM clause, or maybe I'm wrong ?


Okey, solve thanks to this link : http://www.doctrine-project.org/jira/browse/DDC-1047

The key is to reorder the DQL :

$dql = 'SELECT a, s FROM Model_Application a JOIN a.student s, Model_Mission m
        WHERE a.mission = m.id AND m.company = :company';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜