0
votes

Have been having an issue sine using the HABTM relationship in models instead of using a JOIN in the paginate variable in the controller, data comes out fine but I can't set the limit of projects to 20.

I am selecting projects from the DB depeneding on their features.

I havea feature called urgent.

I'm on the urgent listing page.

this should fetch all projects marked with urgent, and it does this fine but it brings back all the results instead of the limit of 20 I set in the paginate function or if I try in the models. here's the pagien array code

$paginate = array(
   'Project' => array(
      'limit' => 20,//works fine when paginating just projects
   ),
   'Feature' => array(
      'limit' => 1, //did set this to 20 but when looking thought well its going to be the limit of the feature table which will only be 1 anyway, notl imit for the projects
      //also tried this below
      'Project' => array(
         'limit' => 20,//no luck with this
      ),
   ),
);

I use this to paginate in my controller

$this->paginate('Feature', array(..conditions..)); //this brings all my projects marked urgent but I only want 20!
2

2 Answers

2
votes

Are you looking for the ContainableBehavior?

$paginate = array(
    'Feature' => array(
        'contain' => array(
            'Project' => array(
                'limit' => 20,
                ....
            )
        )
    )
);
1
votes

I know this is a somewhat dated article, and you're looking for a 1.3 solution, but I used this technique for an application I wrote in 1.2 a while back and it definitely worked: Pagination of data from a HABTM relationship.