I am using below code but Cakephp get out error : "Model "Comment" is not associated with model "User""
$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');
In User model:
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'foreignKey' => 'author',
'dependent' => false
),
);
And in Comment model :
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'author',
)
);