cakephp 3.9
In Categories Model :
$this->hasMany(‘LastArticles’, [
‘className’ => ‘Articles’,
‘foreignKey’ => ‘category_id’,
‘setStrategy’ => ‘select’,
‘queryBuilder’ => function ($q) {
return $q->limit(5);
}
]);
then in categoriesController :
$query = $this->Categories->find()
->select([‘Categories.id’, ‘Categories.name’, ‘Categories.parent_id’])
->contain([
‘ParentCategories’,
‘LastArticles’ => function ($q) {
return $q
->select([‘LastArticles.id’, ‘LastArticles.category_id’, ‘LastArticles.name’, ‘LastArticles.slug’])
->order([‘LastArticles.created’ => ‘DESC’])
;
}
])
->order([‘Categories.lft’ => ‘ASC’])
;
No error but no limit
What’s wrong ?