0

我有以下型号:

运行->hasMany 实际结果

ActualResult 属于 Status

当我查看 ActualResult 时,Cake 无需直接开箱即用即可获得相应的状态。

当我查看运行时,我想对 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' => ''
    )
);
4

0 回答 0