基于关联数据和分页的CakePHP过滤

时间:2012-02-13 01:40:18

标签: cakephp pagination filtering containable

以下是我的情景:

  • 我有两个表:subfirms和subfirmdetails。
  • 我正在尝试对子公司进行分页,但是根据某些子证书价值,例如AUM(公司的总金额),使用过滤器。

这是我的分页代码:

$this->paginate['Subfirm'] = array(
            'contain' => array(
                'Firm' => array(
                    'Firmtype',
                    'conditions' => $firmtype,
                    'Job' => array(
                        'Person'
                    ),
                    'Attachment' => array(
                        'conditions' => array(
                            'Attachment.attachmentgroup_id' => 7
                        ),
                    ),
                ),
                'Subfirmdetail' => array(
                    'Subfirmdetailtype' => array(
                        'Subfirmdetailoption',
                    ),
                ),
                'Substrategy'
            ),
            'order' => array(
                $order,
            ),
            'conditions' => array(
                'Subfirmdetail.value = 40',
            ),
        );

        return $this->paginate('Subfirm');

假设我想要Subfirmdetail.value为40,否则不要显示公司。这是我试图基于(甚至更深......)过滤的场景类型。被困了一段时间,所以任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:2)

您需要使用INNER联接。

 $joins = array(
   array(
       'table' => 'subfirmdetail',
       'alias' => 'Subfirmdetail',
       'type' => 'inner',
       'conditions' => array( 'Subfirmdetail.value = 40', 'Subfirmdetail.subfirm_id = Subfirm.id' )
       ),
   array(
       'table' => 'subfirmdetailtype',
       'alias' => 'Subfirmdetailtype',
       'type' => 'inner',
       'conditions' => array( 'Subfirmdetailtype.subfirmdetail_id = Subfirmdetail.id' )
       ),
   array(
       'table' => 'subfirmdetailoption',
       'alias' => 'Subfirmdetailoption',
       'type' => 'inner',
       'conditions' => array( 'Subfirmdetailoption.subfirmdetailtype_id = Subfirmdetailtype.id' )
       )
   );




  $this->paginate['Subfirm'] = array(
        'fields' => array(
            'Subfirmdetail.*', 'Subfirmdetailtype.*', 'Subfirmdetailoption.*'
            ),
        'joins' => $joins,
        'contain' => array(
            'Firm' => array(
                'Firmtype',
                'conditions' => $firmtype,
                'Job' => array(
                    'Person'
                ),
                'Attachment' => array(
                    'conditions' => array(
                        'Attachment.attachmentgroup_id' => 7
                    ),
                ),
            ),
            'Substrategy'
        ),
        'order' => array(
            $order
        )
    );

    return $this->paginate('Subfirm');

答案 1 :(得分:0)

您可能希望对此使用可点击行为:https://github.com/Terr/linkable