Several "belongs_to" -> how to paginate?

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!

Does this give you what you want?

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

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

Read up on containment. It’s very powerful, and it works anywhere that you’re dealing with queries.