【问题标题】:cakephp unable to sort on afterfind virtual fields with paginatecakephp 无法使用 paginate 对 afterfind 虚拟字段进行排序
【发布时间】:2012-07-07 01:50:11
【问题描述】:

我有一个查询,我正在通过分页运行。此查询包含一个模型(“PaymentException”),该模型具有一个 afterfind 方法,该方法附加上一个“ExceptionWorkflowLog”的副本,并将其称为“LastWorkflowLog”。

传递给分页的查询:

    $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' => 数组(字段和值), 'ExceptionWorkflowLog' => 数组(异常工作流日志), 'LastWorkflowLog' => 数组(最后索引的 ExceptionWorkflowLog 的字段和值) 1 => ...

ExceptionWorkflowLog 通过 PaymentException.id 映射到 PaymentException。这是多对一的关系(因此是 ExceptionWorkflowLog 下的结果数组)。

我想使用分页对最后索引的 ExceptionWorkflowLog 或 LastWorkflowLog 上的“更新”字段进行排序。

有没有办法用分页来做到这一点?目前,如果我将表标题设置为指向“LastWorkflowLog.updated”,则查询返回 false,因为查询不知道“LastWorkflowLog”是什么。

【问题讨论】:

  • 您显示的是PaymentException 或ExceptionWorkflowLogs 的表格吗?这两个模型有什么关系?
  • 这显示了一个查询,它结合了我需要显示的所有内容。我会用关系信息更新问题。
  • 您可以尝试将ExceptionWorkflowLog 绑定为hasOne,并附上一个条件来获取最后一个索引并将其别名为LastWorkflowLog。然后,如果 cake 没有,则强制它进行连接而不是第二次查询,这应该可以工作。
  • 您是在获取当前所有的 ExceptionWorkflowLogs 以获取最后一个,还是将所有记录用于其他目的?在一分钟内,您必须添加 LastWorkflowLog 以包含,如果您不需要所有 ExceptionWorkflowLog,则删除它们。

标签: cakephp cakephp-1.3 cakephp-model


【解决方案1】:

由于这有几百次观看,我想我会回来发布我所做的。 CakePHP 对连接的处理是绝对糟糕的。我重写了查询以不使用连接,而是使用包含。这似乎解决了它。我觉得很脏。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2014-03-15
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 2014-02-21
    • 2013-09-24
    相关资源
    最近更新 更多