我正在使用下面的代码,但 Cakephp 出现错误:“模型“评论”与模型“用户”不相关”
$this->Paginator->settings = array(
'contain' => array_merge(
array(
'Comment' => array(
'limit' => 1,
'User' => array(
'fields' => array('username','id'),
),
)
),
),
'recursive' => 1,
'conditions' => $conditions,
'limit' => 10,
);
$posts = $this->Paginator->paginate('Post');
在用户模型中:
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'author',
'dependent' => false
),
);
在评论模型中:
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'author',
)
);