2012-07-06 98 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。这似乎解决了它。我觉得很肮脏。