Public function view with contain and limit rows

hello World,

is there a possibility to limit the rows of the arrays inside the object? the contain got an arrays of companies but i like to limit to first 10 only ,

      public function view($id = null)
     {
      $warehouse = $this->Warehouses->get($id, [
        'contain' => [' 'Companies'],
     ]);

      $this->set('warehouse', $warehouse);
      }

i tried but came out error [ Warning (2)](javascript:void(0);): Illegal offset type in isset or empty [ CORE/src/ORM/EagerLoader.php , line 410 ]

      'contain' => [' 'Companies']->find('all', array('limit' => 10));

would like to humbly learn from anyone how can i limit the arrays inside contain

thank you
:raised_hands: :raised_hands: :raised_hands:

The syntax you’re looking for is here. The examples there are largely about adding “where” clauses to contain specific matches only, but you can also use “limit” or anything else that a query can include.

Dear Zuluru,

thank you very much, i will give it a try, from the cakephp side here, the data load is very heavy, at least 2000 rows in a table so when it loads via api, its very slow. im thinking of limiting the get data for getting 10 first, then the rest i create another function to load it slowing.

Just limiting can be done with what Zuluru already told you.

But if you want to paginate related/associated data you will most likely need this plugin

Hello Kevin,

thank you very much for your help, i will try to learn the pagination icings, Zuluru array limiting part i have completed and ok, will update about the icings soon.

regards and have a nice day/night?

:raised_hands: :raised_hands: :bowing_man:

2000 rows in a table so when it loads via api, its very slow. im thinking of limiting the get data for getting 10 first, then the rest i create another function to load it slowing.