Question

I am trying to do a fairly simple CakePHP find using the Containable behavior:

$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id),
    'contain' => array(
        'Comp.id' => array(
            'fields' => array('Comp.id'),
        ),
        'Slot' => array(
            'fields' => array(
                'Slot.start_time',
                'Slot.end_time'
            )
        ),
        'Team'
    )
));

...but upon execution a warning is shown:

Warning (512): Model "Comp" is not associated with model "Comp" [CORE/cake/libs/model/behaviors/containable.php, line 363]

The start of my Comp model is as follows:

var $name = 'Comp';
var $hasMany = array('Team', 'Round', 'Match');
var $belongsTo = array('Generation');
var $hasAndBelongsToMany = array('Slot');
var $actsAs = array('Containable');

I am using CakePHP 1.3.6

Any ideas what may be causing this?

Was it helpful?

Solution

$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id),
    'fields'     => array('Comp.id'),
    'contain'    => array(
        'Slot'       => array(
            'fields'     => array(
                'Slot.start_time',
                'Slot.end_time'
            )
        ),
        'Team'
    )
));

You told it to contain the related Comp.id, which means the model Comp related to Comp, which doesn't exist. You probably meant to simply set the fields option of the Comp model itself?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top