2012-09-29 61 views
2

我已經使用查詢生成器構建了正確的工作查詢。將列動態添加到列列表

但是現在有一個條件,其中一個方法(負責動態地將一些表格添加到查詢中)必須向查詢添加一列。

我試過以下(這要複雜得多,但它幾乎是相同的):提前

回答

1

$querybuilder->select('EntityA.Property') 
      ->from ('EntityA'); 

// here is happening some awesome stuff... ;-) 
// Now i have to add the Table, and The column 

$querybuilder->innerJoin('EntityB'); // this is working 
$querybuilder->add('select', 'EntityB.Property'); // overwrites my columnlist 
// $querybuilder->select('EntityB.Property'); // also overwrites my columnlist 

感謝你爲什麼不只是組裝選擇子句seperately這樣:

$fields = array(); 

$fields[] = "EntityA.Property" 

// code here, and finally, you decide you need EntityB 
$fields[] = "EntityB.Property" 
$querybuilder->innerJoin('EntityB'); 

// done with building the query, assign select 
$querybuilder->select($fields); 
+0

hm,它更簡單, - > select()可以處理數組; - ),但是通過方法添加它會很好,所以我不必傳遞一個新參數。但是,謝謝,它會工作 – RomanKonz

+0

我會編輯我的答案,以反映 – adhominem