2013-08-01 71 views
1

這讓我瘋狂。這不會引發任何錯誤,但它也不會執行連接。我希望這是一個,我已經花了太長時間看着它,答案是顯而易見的給別人...CakePHP加入問題

 $lines = $this->RevenueLine->find('all', array(
       'conditions' => array(
        'RevenueLine.is_triggered' => 1, 
        'RevenueLine.date_triggered >=' => $sqldate1, 
        'RevenueLine.date_triggered <=' => $sqldate2, 
       ), 
       'joins' => array(
        array(
         'table' => 'projects', 
         'alias' => 'Project', 
         'type' => 'INNER', 
         'conditions' => array(
          'RevenueLine.project_id = Project.id' 
         ) 
        ), 
        array(
         'table' => 'clients', 
         'alias' => 'Client', 
         'type' => 'INNER', 
         'conditions' => array(
          'Project.client_id = Client.id' 
         ) 
        ), 
        array(
         'table' => 'classifications', 
         'alias' => 'Classification', 
         'type' => 'INNER', 
         'conditions' => array(
          'Project.classification_id = Classification.id' 
         ) 
        )      
       ), 
       'order' => array(
        'Client.client_number ASC', 
        'Project.pn_counter ASC' 
       ) 
      ) 
     ); 
+0

它是做什麼的?它只是返回0行嗎? –

+0

它從RevenueLine表中提取所有內容,但是沒有其他內容。與LEFT JOIN相同的結果 – gazareth

回答

2

您需要選擇從連接表中的字段:

'fields' => array(
    'JoinTable1.*', 
    'JoinTable2.*', 
    'JoinTable3.*', 
    'JoinTable4.*' 
) 

作爲您查找的參數。

+0

已解決問題,謝謝。我*發誓*我已經運行了其他類似這樣的發現而沒有指定字段,並且它自動從每個表(包括連接)中提取所有字段。 :-) – gazareth

+0

很好:)很高興我能幫到 –

+0

謝謝巴里!我也有同樣的問題!這在食譜中沒有提及... http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables –