The CakePHP 5 documentation says you can use $this->paginate = [ 'contain' => ['Users']];
to include associations here => https://book.cakephp.org/5/en/controllers/pagination.html#joining-additional-associations
I’ve tried the above with a fresh install of CakePHP 5 and it doesn’t seem to work any idea what could be the problem?
public function index()
{
// user association is included
$query = $this->Posts->find()
->contain(['Users']);
$paginatedQuery = $this->paginate($query);
// this doesn't work
$this->paginate = [
'contain' => ['Users']
];
$paginatedModel = $this->paginate('Posts');
dd([
$paginatedQuery->first()->toArray(),
$paginatedModel->first()->toArray()
]);
}