cakephp - CakePHP3.x fetching associated data from controller -


i have relations postcategory hasmany posts , post hasone user. here code fetches posts not able users data 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 null','postcategories.active'=>1])         ->hydrate(false)->toarray(); 

also want 5 latest posts each category. code fetches 5 posts first category , blank array remaining categories.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -