2011-09-07 56 views
2

PHP代碼:主義的DBAL查詢生成器omitts一些加入

$xCodesQueryBuilder = $conn->createQueryBuilder(); 

    $xCodesQueryBuilder->select("l.id","mdsh.xcode","mdso.xcode") 
      ->from("location_tree","l") 
      ->join("l","location_tree_pos","p","l.id = p.tree_id") 
      ->rightJoin("l","hotel","h","h.location_id = l.id") 
      ->leftJoin("l","offer_location","ol","l.id=ol.location_id") 
      ->leftJoin("ol","mds_offer","mdso","ol.offer_id = mdso.offer_id") 
      ->leftJoin("h","mds_hotel","mdsh","h.id = mdsh.hotel_id") 
      ->where("p.parent_id IN (:ids)") 
      ->andWhere("(mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL)"); 

    var_dump($xCodesQueryBuilder->getSQL());exit; 

結果:

SELECT l.id, mdsh.xcode, mdso.xcode 
FROM location_tree l 
INNER JOIN location_tree_pos p ON l.id = p.tree_id 
RIGHT JOIN hotel h ON h.location_id = l.id 
LEFT JOIN offer_location ol ON l.id=ol.location_id 
WHERE (p.parent_id IN (:ids)) 
AND ((mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL)) 

任何想法,爲什麼最後2個連接被省略?

+0

一些reaseon每個第一個參數加入必須是相同的(「L」的我的情況),然後它的工作。任何人都可以解釋這背後的邏輯嗎? – Itako

+0

我有同樣的問題。只有那些與「FROM」表別名關聯的連接纔會出現。其他一切似乎都被省略了。 – anushr

回答

3

我剛剛爲我工作。必須在QueryBuilder.php中修改功能getSQLForSelect()

我已經打開了一個ticket並向DBAL提交了一個請求,但是在此期間,請隨時使用my patched copy

UPDATE:

剛剛意識到解決這個問題的另一種方法是始終使用FROM表的別名在任何join()方法的第一個參數($fromAlias)。

在你的情況,你會改變你的代碼看起來像這樣:

$xCodesQueryBuilder = $conn->createQueryBuilder(); 

$xCodesQueryBuilder->select("l.id","mdsh.xcode","mdso.xcode") 
     ->from("location_tree","l") 
     ->join("l","location_tree_pos","p","l.id = p.tree_id") 
     ->rightJoin("l","hotel","h","h.location_id = l.id") 
     ->leftJoin("l","offer_location","ol","l.id=ol.location_id") 
     ->leftJoin("l","mds_offer","mdso","ol.offer_id = mdso.offer_id") 
     ->leftJoin("l","mds_hotel","mdsh","h.id = mdsh.hotel_id") 
     ->where("p.parent_id IN (:ids)") 
     ->andWhere("(mdso.xcode IS NOT NULL OR mdsh.xcode IS NOT NULL)"); 

var_dump($xCodesQueryBuilder->getSQL());exit; 
0

我想學說2.3.1支持這一點。

解決方法可能會將連接轉換爲來自哪裏,如果需要使用分組。 卡住了2-3小時,最後用這個解決辦法 因爲即使升級後不幫我(試圖找出原因)