自我加入模特

时间:2013-06-02 21:59:43

标签: cakephp-1.3

我的模型如下

class SentSms extends AppModel {
var $name = "Sentsms";

var $hasMany =  array(
                    'SentSms1' => array(
                            'className' => 'SentSms',
                            'order'                => 'SentSms1.sql_id DESC',
                                'foreignKey'   => 'parent_key'));
var $belongsTo =  array(
                        'SentSms2' => array(
                                'className' => 'SentSms',
                                'order'                => 'SentSms2.sql_id DESC',
                                'foreignKey'   => 'parent_key'));
}

控制器代码如下:

$this->paginate = array('conditions' => array('service' => $this->Session->read('Auth.User.username'), 'momt' => 'MT'),
                                        'limit' => 25,
                                        'recursive' => '1',
                                        'order' => array('sql_id desc')
    );
    $report = $this->paginate('SentSms');

这里正在执行简单的选择查询。我是CakePhp的新手并且一整天坚持下去。

1 个答案:

答案 0 :(得分:0)

递归是数字属性,你应该这样改变你的代码:

$this->paginate = array('conditions' => array('service' => $this->Session->read('Auth.User.username'), 'momt' => 'MT'),
                                        'limit' => 25,
                                        'recursive' => 1,   //change '1' to 1
                                        'order' => array('sql_id desc')
    );