1
我有兩個與HABTM(文檔和人員)相關的模型。HABTM數據未保存(cakephp)
class Person extends AppModel {
var $name = 'Person';
var $hasAndBelongsToMany = array(
'Document' => array(
'className' => 'Document',
'joinTable' => 'documents_people',
'foreignKey' => 'person_id',
'associationForeignKey' => 'document_id',
'unique' => false
)
);
class Document extends AppModel {
var $name = 'Document';
var $hasAndBelongsToMany = array(
'Person'=>array(
'className' => 'Person',
'joinTable' => 'documents_people',
'foreignKey' => 'document_id',
'associationForeignKey' => 'person_id',
'unique' => false
)
);
我有一個複選框填充的文件添加視圖,每個人將與文檔相關。
echo $form->input('People', array('type'=>'select', 'multiple'=>'checkbox', 'options'=>$people, 'label' => 'People: '));
這是不同於應該做節約控制器的線。
$this->Document->create();
if ($this->Document->saveAll($this->data)) {
我注意到數據沒有被保存到documents_people表中。所以,我傾倒了$ this-> data。
文檔部分看起來是這樣的:
[Document] => Array
(
[file_name] => asdasd
[tags] => habtm
[People] => Array
(
[0] => 6
[1] => 12
[2] => 15
)
[image] => img/docs/2009-11-19-233059Jack.jpg
)
這些都是我想與此文檔相關人的ID。但是,沒有任何內容傳遞給documents_people。我做錯了什麼?
那麼簡單,而是正確的。 – 2009-11-23 15:57:15