使用contain进行Cakephp分页会产生“未关联”警告
我有以下型号: 运行->有许多实际结果 ActualResult属于状态 当我查看ActualResult时,Cake会获得相应的状态,而不会直接显示出来 查看跑步时,我希望对实际结果进行分页。在RunsController::view中,我已设法使其与以下代码一起工作:使用contain进行Cakephp分页会产生“未关联”警告,cakephp,pagination,contain,Cakephp,Pagination,Contain,我有以下型号: 运行->有许多实际结果 ActualResult属于状态 当我查看ActualResult时,Cake会获得相应的状态,而不会直接显示出来 查看跑步时,我希望对实际结果进行分页。在RunsController::view中,我已设法使其与以下代码一起工作: public function view($id = null) { if (!$this->Run->exists($id)) { throw new NotFoundEx
public function view($id = null) {
if (!$this->Run->exists($id)) {
throw new NotFoundException(__('Invalid run'));
}
$this->Run->contain ( 'Pack', 'User', 'Status');
$options = array('conditions' => array('Run.' . $this->Run->primaryKey => $id));
$run = $this->Run->find('first', $options);
$this->set('run', $run);
// Paginate the ActualResults
$this->paginate = array(
'contain' => array('Status'),
'order' => 'ActualResult.format',
'limit'=>5 ,
'conditions' => array('ActualResult.run_id' => $id)
);
$actualResults = $this->Paginator->paginate('ActualResult');
$this->set('actualResults',$actualResults);
}
问题是我得到了一个警告:
警告512:模型实际结果与模型状态[CORE\Cake\Model\Behavior\ContainableBehavior.php,第343行]无关
在另一个模型关联中,类似的东西对我起作用,正如在ActualResultController中提到的视图很好,所以我被难住了。
有人能帮忙吗
以下是模型关联:
在Run.php中:
public $hasMany = array(
'ActualResult' => array(
'className' => 'actual_result',
'foreignKey' => 'run_id',
'dependent' => true,
'finderQuery' => 'SELECT ActualResult.*, Txn.name, Status.name FROM actual_results AS ActualResult, txns as Txn, codes AS Status WHERE ActualResult.run_id = {$__cakeID__$} and Txn.id = ActualResult.txn_id and (Status.code = ActualResult.status and Status.code_type = "ARS");'
)
);
在ActualResult.php中
public $belongsTo = array(
'Run' => array(
'className' => 'Run',
'foreignKey' => 'run_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Status' => array(
'class`enter code here`Name' => 'Code',
'foreignKey' => 'status',
'conditions' => 'code_type = "ARS"',
'fields' => '',
'order' => ''
)
);
这一行是什么?:$this->Run->contain'Pack'、'User'、'Status';@Dave这是为了在Run find中不获取实际结果-因为我试图在代码的后半部分分别获取分页的实际结果。Run还与Status有自己的关联-独立于实际结果关联。