我有一個奇怪的問題與主義查詢,與Symfony的2.3學說2 LEFT JOIN不會檢索所有列
(由提前,在我的查詢英文/法文術語抱歉..:S)
時,在我的控制,我發動我的資料庫之一的findAll()查詢,生成以下查詢:
SELECT t0.id AS id1, t0.date AS date2, t0.projet_id AS projet_id3, t0.societe_id AS societe_id4, t0.user_id AS user_id5 FROM Estimate t0
因此,我把我的所有列包括涉及關係的人。 但我需要在我的查詢中添加左連接。我創建了一個自定義查詢:
$qb = $this->createQueryBuilder('e')
->addSelect('e')
->leftJoin('e.works', 'w')
->addSelect('w')
->leftJoin('w.tache', 't')
->addSelect('t')
->leftJoin('t.groupetache', 'g')
->addSelect('g')
;
,現在,我得到了所有的聯接的列,但我的主表「估計」,則查詢僅返回ID和日期(生成以下查詢:)
SELECT e0_.id AS id0, e0_.date AS date1, w1_.id AS id4, w1_.description AS description5, w1_.prix_ha AS prix_ha6, w1_.prix_vente AS prix_vente7, t2_.id AS id8, t2_.nom AS nom9, t2_.prix_achat AS prix_achat10, g3_.id AS id11, g3_.nom AS nom12 FROM Estimate e0_ LEFT JOIN Work w1_ ON e0_.id = w1_.estimate_id LEFT JOIN Tache t2_ ON w1_.tache_id = t2_.id LEFT JOIN GroupeTaches g3_ ON t2_.groupetache_id = g3_.id
我錯過了一個觀點嗎?
有一種方法可以讓我所有的主表字段,加入的字段正確嗎?
在續集專業回報我的「使用說明書」查詢我想要什麼,我試圖改變我的查詢與DQL一個,像這樣:
$query = $this->getEntitymanager()
->createQuery('
SELECT e0_.id AS id0, e0_.date AS date1, e0_.id AS id2, e0_.date AS date3,
e0_.projet_id AS projet_id3, e0_.societe_id AS societe_id4, e0_.user_id AS user_id5,
w1_.id AS id4, w1_.description AS description5, w1_.prix_ha AS prix_ha6, w1_.prix_vente AS prix_vente7,
t2_.id AS id8, t2_.nom AS nom9, t2_.prix_achat AS prix_achat10, g3_.id AS id11, g3_.nom AS nom12
FROM EcomCrmBundle:Estimate e0_
LEFT JOIN EcomCrmBundle:Work w1_ WITH e0_.id = w1_.estimate_id
LEFT JOIN EcomCrmBundle:Tache t2_ WITH w1_.tache_id = t2_.id
LEFT JOIN EcomCrmBundle:GroupeTaches g3_ WITH t2_.groupetache_id = g3_.id');
,但我有一個錯誤,說估計沒有按」噸有一個projet_id場:(
在此先感謝您的幫助。
我們能否看到我們的實體? –
我想你可以嘗試清除緩存等。有沒有可能你有兩個數據庫副本?使用多個實體管理器? EcomCrmBundle的兩個副本:估計?在同一個控制器中一個接一個地執行兩個查詢?很奇怪。 – Cerad