cakephp无法使用paginate对afterfind虚拟字段进行排序

时间:2012-07-06 15:15:11

标签: cakephp cakephp-1.3 cakephp-appmodel

我有一个查询,我正在通过paginate运行。此查询包含一个模型(“PaymentException”),该模型具有一个后处理方法,该方法处理最后一个“ExceptionWorkflowLog”的副本,并将其称为“LastWorkflowLog”。

传递给paginate的查询:

    $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 个答案:

答案 0 :(得分:0)

由于这有几百个视图,我想我会回来发布我所做的。 CakePHP对连接的处理非常糟糕。我重写了查询以不使用连接,但使用包含。这似乎解决了它。我觉得很脏。