# Several "belongs\_to" -\> how to paginate?

**URL:** <https://discourse.cakephp.org/t/several-belongs-to-how-to-paginate/7545>\
**Category:** Need Help\
**Created:** [March 26, 2020, 10:58am UTC](https://discourse.cakephp.org/t/several-belongs-to-how-to-paginate/7545 "2020-03-26T10:58:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roridula](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roridula](https://discourse.cakephp.org/u/Roridula)\
**Post date:** [March 26, 2020, 10:58am UTC](https://discourse.cakephp.org/t/several-belongs-to-how-to-paginate/7545/1 "2020-03-26T10:58:29Z")

</div>

In my database I have measurements that I want to paginate (index view). These measurements belong to samples. The samples belong to items and these items belong to companies.

Companies have many items, items have many samples, samples have many measurements.

I get the first connection to samples in the MeasurementsController.php  
$this-\>paginate = [‘contain’ =\> [‘Samples’]];

But how can I include articles and companies? I am using cakephp4.x

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 26, 2020, 3:32pm UTC](https://discourse.cakephp.org/t/several-belongs-to-how-to-paginate/7545/2 "2020-03-26T15:32:15Z")

</div>

Does this give you what you want?

```
$this->paginate = ['contain' => ['Samples' => ['Items' => ['Companies']]]];
```

---

<div class="post-metadata">

**Author:** ![Roridula](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@Roridula](https://discourse.cakephp.org/u/Roridula)\
**Post date:** [March 26, 2020, 4:03pm UTC](https://discourse.cakephp.org/t/several-belongs-to-how-to-paginate/7545/3 "2020-03-26T16:03:30Z")

</div>

Great, thank you. So simple! But I would not have guessed that.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 26, 2020, 9:58pm UTC](https://discourse.cakephp.org/t/several-belongs-to-how-to-paginate/7545/4 "2020-03-26T21:58:27Z")

</div>

Read up on [containment](https://book.cakephp.org/3/en/orm/retrieving-data-and-resultsets.html#eager-loading-associations-via-contain). It’s very powerful, and it works anywhere that you’re dealing with queries.
