# How can I paginate an associated model?

**URL:** <https://discourse.cakephp.org/t/how-can-i-paginate-an-associated-model/1455>\
**Category:** Need Help\
**Created:** [November 4, 2016, 4:52pm UTC](https://discourse.cakephp.org/t/how-can-i-paginate-an-associated-model/1455 "2016-11-04T16:52:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SharonGilmore](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/sharongilmore/32/423_2.png) [@SharonGilmore](https://discourse.cakephp.org/u/SharonGilmore)\
**Post date:** [November 4, 2016, 4:52pm UTC](https://discourse.cakephp.org/t/how-can-i-paginate-an-associated-model/1455/1 "2016-11-04T16:52:24Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [November 5, 2016, 3:21am UTC](https://discourse.cakephp.org/t/how-can-i-paginate-an-associated-model/1455/2 "2016-11-05T03:21:06Z")

</div>

Leave parenthesis blank:

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

```

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

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

```

---

<div class="post-metadata">

**Author:** ![SharonGilmore](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/sharongilmore/32/423_2.png) [@SharonGilmore](https://discourse.cakephp.org/u/SharonGilmore)\
**Post date:** [November 11, 2016, 4:29pm UTC](https://discourse.cakephp.org/t/how-can-i-paginate-an-associated-model/1455/3 "2016-11-11T16:29:58Z")

</div>

Thank you! That’s helpful.

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [November 11, 2016, 5:12pm UTC](https://discourse.cakephp.org/t/how-can-i-paginate-an-associated-model/1455/4 "2016-11-11T17:12:48Z")

</div>

Glad it helped you out.
