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。任何建议?
非常感谢您对我的英语感谢。