1

我得到了这个模型:

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");

}

我正在尝试像这样对 CompanyRestaurantRequest 进行分页:

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

问题是我没有得到 CompanyRestaurantRequestFeedResponse。

我尝试将 ContainableBehavior 附加到 CompanyRestaurantRequest 模型,并在分页设置中使用了包含键,如下所示:

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

无论我尝试什么,我都无法获得与 CompanyRestaurantRequestFeeds 相关的那些 CompanyRestaurantRequestFeedResponses。

我怎样才能让它工作?

谢谢!

4

1 回答 1

0

代替行:

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

在声明所有 var 的 Controller 顶部添加:

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

这应该解决它...

于 2012-09-18T13:37:51.683 回答