我有两个与HABTM相关的模型(文档和人物)。
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->数据。
文档部分如下所示:
[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。我做错了什么?
答案 0 :(得分:7)
也许你的$this->data
数组应该有一个'Person'部分,而不是复数'People'
你试过......
echo $form->input('Person'.....