简体   繁体   中英

CakePHP: pagination with recursive queries not working as expected

I got this models:

class CompanyRestaurantRequest extends AppModel
{
    public $name = "CompanyRestaurantRequest";      
    //public $actsAs = array('Containable');        
    public $hasMany = array(
        "UserRestaurantRequestFeed" => array(
            'dependent' => true
        )
    );
}

class UserRestaurantRequestFeed extends AppModel{
    public $name = "UserRestaurantRequestFeed";         
    public $belongsTo = array("CompanyRestaurantRequest");
    public $hasMany = array("UserRestaurantRequestFeedResponse");
}

class UserRestaurantRequestFeedResponse extends AppModel{
    public $name = "UserRestaurantRequestFeedResponse";

    public $belongsTo = array("UserRestaurantRequestFeed");

}

and I am trying to paginate CompanyRestaurantRequest like this:

$this->CompanyRestaurantRequest->recursive = 5;
$this->CompanyRestaurantRequestFeed->recursive = 5;
$this->paginate = array(
    'limit' => 10,
    'order' => array(
             'CompanyRestaurantRequest.id' => 'desc'
    )
);
$this->set('requests', $this->paginate("CompanyRestaurantRequest"));

The problem is that I get no CompanyRestaurantRequestFeedResponse.

I tried to attach ContainableBehavior to the CompanyRestaurantRequest model and I used contain key in paginate settings like this:

'contain' => array('CompanyRestaurantRequestFeedResponse');

Anything I try, I can not get those CompanyRestaurantRequestFeedResponses related to CompanyRestaurantRequestFeeds.

How can I make it work?

Thank you!

Intead of lines:

$this->paginate = array(
  'limit' => 10,
  'order' => array(
         'CompanyRestaurantRequest.id' => 'desc'
  )
);

At the top of the Controller where all var are declared add:

public $paginate = array(
  'CompanyRestaurantRequest' => array(
    'limit' => 10,
    'order' => array(
      'CompanyRestaurantRequest.id' => 'desc'
    )
  )
);

This should fix it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM