在 cakePHP 中连接和计数表

Join and Count Tables in cakePHP

感谢我在学习 php 时在 Whosebug 上获得的帮助,我能够加入 tables 并使用 Count。

我无法在一个查询中同时执行这两项操作。

我想计算已连接 table 中的记录数。 这是我尝试过的方法,但我似乎遇到了错误:

$options = array(
    'fields' => array(
        'toutcome.AffCommission',
    ),
    'joins' => array(

        array(
            'conditions' => array(
                'tapplicant.AppID = toutcome.AppID',
            ),
            'table' => 'toutcome',
            'alias' => 'Toutcome',
            'type' => 'join',
        ),
    ),
    'limit' => 'Toutcome',
    'offset' => 'Toutcome',
    'contain' => array(
        'Toutcome',
    ),
);

$data = $this->Tapplicant->find('count', $options);
$this->set('count', $data );

试试这个

$options = array(
    'fields' => array(
        'toutcome.AffCommission',
    ),
    'joins' => array(

        array(
            'conditions' => array(
                'tapplicant.AppID = toutcome.AppID',
            ),
            'table' => 'toutcome',
            'alias' => 'Toutcome',
            'type' => 'join',
        ),
    ),
    'limit' => n, // its should be integer
    'offset' => n, // its should be integer
    'contain' => array(
        'Toutcome',
    ),
);