0

I've got the following models:

Run->hasMany ActualResult

ActualResult belongs to Status

When I view an ActualResult, Cake gets the corresponding Status without straight out of the box.

When I view a Run, I want to paginate the ActualResults. I have managed to get this to almost work with the following code in 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);
    }

The problem is that I get a warning: Warning (512): Model "ActualResult" is not associated with model "Status" [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 343

Something v. similar works for me in another model association, and as mentioned view() in ActualResultController works fine, so I am stumped. Can anyone help?

Here are the model assocations: In 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");'
    )
);

In 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' => ''
    )
);
pkbevans
  • 23
  • 4
  • What is this line?: `$this->Run->contain ( 'Pack', 'User', 'Status');` – Dave Jul 21 '14 at 01:31
  • @Dave This is to NOT get the ActualResults in the Run find - because I am trying to get the paginated ActualResults separately in the 2nd half of the code. Run also has its own association with Status - separate to the ActualResult association. – pkbevans Jul 21 '14 at 06:34

0 Answers0