1
我有一個與cakephp habtm的問題,我不知道如何解決。我有三張表:setores,veiculos和setores_veiculos。CakePHP 2.x HABTM返回沒有匹配的結果
Setor型號:
public $hasAndBelongsToMany = array(
'Veiculo' => array(
'className' => 'Veiculo',
'joinTable' => 'setores_veiculos',
'foreignKey' => 'setor_id',
'associationForeignKey' => 'veiculo_id',
'unique' => 'keepExisting'
)
);
Veiculo型號:
public $hasAndBelongsToMany = array(
'Setor' => array(
'className' => 'Setor',
'joinTable' => 'setores_veiculos',
'foreignKey' => 'veiculo_id',
'associationForeignKey' => 'setor_id',
'unique' => 'keepExisting'
)
);
在我setores控制器我有:
$options = array('conditions' => array('Setor.' . $this->Setor->primaryKey => $id));
$setores = $this->Setor->find('first', $options);
然後在我的調試:
array(
'Setor' => array(
'id' => (int) 5,
'nome' => '2º Batalhão',
'secretaria_id' => (int) 6,
'sigla' => '2º BPM',
'status_id' => (int) 1
),
'Veiculo' => array()
)
我不明白爲什麼沒有被列出的Veiculo(車輛)。插入工作正常。
我預計:
'Veiculo' => array(
0 => array(
'id' => 1,
'name' => 'Corolla'
),
1 => array(
'id' => 2,
'name' => 'Hillux'
)
);
在我veiculos控制器被列出的setores。任何建議?
非常感謝您對我的英語感謝。