I have two models, named Post and Comment, which are linked by Post hasMany Comment and Comment belongsTo Post.
I want to fetch all posts with the first five comments each. I would use this code:
$this->Posts->find(‘all’)
->contain([
‘Comments’ => function($q) {
return $q
->order(‘created ASC’)
->limit(5);
}
]);
This works incorrectly with the limit(5). Please help to solve this.