Domanda

Sto cercando di fare un abbastanza semplice trovare CakePHP utilizzando il comportamento contenibile:

$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'
    )
));

... ma al momento dell'esecuzione viene visualizzato un messaggio di avviso:

Attenzione (512): Modello "Comp" non è associato con il modello "Comp" [Core / torta / librerie / modello / comportamenti / containable.php, linea 363]

L'inizio del mio modello Comp è la seguente:

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

Sto usando CakePHP 1.3.6

Tutte le idee che possono causare questo?

È stato utile?

Soluzione

$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'
    )
));

Hai detto al contain il relativo Comp.id, il che significa che il modello Comp relative al Comp, che non esiste. Probabilmente significava semplicemente impostare l'opzione fields del modello Comp stessa?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top