使用contains的Cakephp分页会产生“无关联”警告

时间:2014-07-20 20:57:27

标签: cakephp pagination contain

我有以下型号:

运行 - > hasMany ActualResult

ActualResult属于Status

当我查看ActualResult时,Cake会立即获得相应的状态。

当我查看Run时,我想对ActualResults进行分页。我已经成功地使用了RunsController :: view()中的以下代码:

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):型号" ActualResult"与模型"状态"无关。 [CORE \ Cake \ Model \ Behavior \ ContainableBehavior.php,第343行

某些东西与另一个模型关联中的类似作品,并且如在ActualResultController中提到的view()工作正常,所以我很难过。 有人可以帮忙吗?

以下是模型关联: 在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' => ''
    )
);

0 个答案:

没有答案