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