2012-07-06 28 views
1

我有一個查詢,我通過頁面運行。該查詢包含一個模型(「PaymentException」),該模型具有一個後綴方法,該方法添加上一個「ExceptionWorkflowLog」的副本,並將其稱爲「LastWorkflowLog」。cakephp無法排序後處理虛擬字段與頁面

正在傳遞的查詢進行分頁:

$this->paginate = array(
     'fields' => array(
      'PaymentException.*', 'Procedure.id', 'Procedure.cpt', 
      'Procedure.expected_amount', 'Procedure.allowed_amount', 'Procedure.difference_amount', 
      'Claim.id', 'Claim.number', 'Payer.abbr' 
     ), 
     'limit' => 50, 
     'joins' => array(
      array(
       'table' => 'procedures', 
       'alias' => 'Procedure', 
       'conditions' => array('Procedure.id = PaymentException.procedure_id') 
      ), 
      array(
       'table' => 'claims', 
       'alias' => 'Claim', 
       'conditions' => array('Claim.id = Procedure.claim_id') 
      ), 
      array(
       'table' => 'payers', 
       'alias' => 'Payer', 
       'conditions' => array('Payer.id = Procedure.payer_id') 
      ), 
      array(
       'table' => 'groups', 
       'alias' => 'Groups', 
       'conditions' => array('Groups.id = Claim.group_id') 
      ) 
     ), 
     'conditions' => $conditions, 
     'contain' => array('ExceptionWorkflowLog') 
    ); 

所得陣列(從結合了 「PaymentException」 查詢 「ExceptionWorkflowLog」 和 「LastWorkflowLog」)看起來像下面:

 
0 => 
    'PaymentException' => array(fields and values), 
    'ExceptionWorkflowLog' => array(of ExceptionWorkflowLogs), 
    'LastWorkflowLog' => array(fields and values of the last indexed ExceptionWorkflowLog) 
1 => ... 

ExceptionWorkflowLog通過PaymentException.id映射到PaymentException。這是一個多對一的關係(因此在ExceptionWorkflowLog下的結果數組)。

我想使用paginate排序最後索引的ExceptionWorkflowLog或LastWorkflowLog上的「updated」字段。

有沒有辦法用paginate做到這一點?目前,如果我將表標題設置爲指向「LastWorkflowLog.updated」,則查詢返回false,因爲查詢不知道「LastWorkflowLog」是什麼。

+1

您是在顯示'PaymentException'還是'ExceptionWorkflowLogs'表?這兩種模式之間的關係是什麼? – tigrang 2012-07-06 18:05:05

+0

這顯示了一個查詢,它結合了我需要顯示的所有內容。我會用關係信息更新問題。 – tubaguy50035 2012-07-06 18:06:19

+1

您可以嘗試將'ExceptionWorkflowLog'綁定爲'hasOne',並使用條件來抓取最後一個索引的並將其別名爲LastWorkflowLog。然後,如果蛋糕沒有,強迫它做一個連接而不是第二個查詢,這應該工作。 – tigrang 2012-07-06 18:11:08

回答

0

由於這有幾百個意見,我想我會回來發佈我做的。 CakePHP處理連接是非常糟糕的。我重寫了查詢以不使用連接,但使用了contains。這似乎解決了它。我覺得很骯髒。