I have relations Postcategory hasMany Posts and Post hasOne User. Here is my code which fetches the posts but I am not able to get users data for each post.
$parents = $postcategories->find('all',[
'fields'=>['Postcategories.id','Postcategories.name'],
])->contain(['Posts'=>function ($q) {
return $q->select(['id', 'title','postcategory_id'])
->where(['Posts.active' => 1])
->order('Posts.created DESC')
->limit(5)
;}])
->where(['Postcategories.parent_id is null','Postcategories.active'=>1])
->hydrate(false)->toArray();
Also I want only 5 latest posts for each category. This code fetches only 5 posts for first category and blank array for remaining categories.