How can I paginate an associated model?

I have 2 models, Subsite and News, with a belongsToMany association.

I’m trying to retrieve a Subsite and its associated News items. This bit is fine, but I’d like to paginate the News items which are returned.

My find query is:

        $query = $subsites->find('all')
                                ->where(['Subsites.name' => $subsite])
                                ->contain(['News']);

I’m not sure whether it’s possible to paginate the News items or not; if so, where do I put the pagination array? I tried putting the following in my SubsitesTable:

    public $paginate = [
        'News' => [
            'limit' => 25,
            'order' => [
                'News.date' => 'desc'
            ]
        ]
    ];

but I still get all news items returned. Thanks!

Leave parenthesis blank:

$query = $subsites->find()
                                ->where(['Subsites.name' => $subsite])
                                ->contain(['News']);

Something like that. In one of mine I use a custom pagination and looks like:

$query = $dogs->find()
                ->where(['adopted' => 0])
                ->orderAsc('sex')
                ->orderDesc('lastedit')
                ->limit($rowsperpage)
                ->page($pg);

Thank you! That’s helpful.

Glad it helped you out.