I have a CakePHP 3 application which has 2 models, Urls and Downloads. The models are associated such that a URL may have multiple downloads (Urls hasMany Downloads in Cake terminology).
When I do a query such as this it will return 1 row from the Urls table and all of the associated Downloads:
// This is in a view() method
$query = $this->Urls->find()->contain(['Downloads' => ['sort' => ['Downloads.created' => 'DESC'] ] ])->where(['id' => $id]);
I want to paginate the list of Downloads but can't see how to do this. I've taken a look at https://book.cakephp.org/3.0/en/controllers/components/pagination.html but the only thing I could find which I tried was:
public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
}
// In my view() method
$this->paginate = [
'contain' => ['Downloads']
];
$query = $this->Urls->find()->contain(['Downloads' => ['sort' => ['Downloads.created' => 'DESC'] ] ])->where(['id' => $id])->paginate();
But it just errors saying Unknown method "paginate"
paginate()method isn't a method of the table class. - ndm