ItGo.me Focus on IT Recommend

Home > save - HABTM data not saving (cakephp)

save - HABTM data not saving (cakephp)

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
入口地址https://www.aliyun.com/minisite/goods

up vote 1 down vote favorite 2 I have two models related HABTM (documents and people). 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

)

);

I have the add view of documents populated with one checkbox for each person that will be related to the document.

echo $form->input('People', array('type'=>'select', 'multiple'=>'checkbox', 'options'=>$people, 'label' => 'People: '));

This is the line from the controller that is supposed to be doing the saving. $this->Document->create();

if ($this->Document->saveAll($this->data)) {

I noticed that the data was not getting saved into the documents_people table. So, I dumped $this->data. The document portion looks like this: [Document] => Array

(

Recommend:has and belongs to many - CakePHP find HABTM

e Message belongsto User Message HABTM Tag Tag HABTM Message If a User is logged in he might want to see all Message tagged with something. $messages = $this->Message->find('all', array(

'conditions' => array("Message.user_id" => $this-

[file_name] => asdasd

[tags] => habtm

[People] => Array

(

[0] => 6

[1] => 12

[2] => 15

)

[image] => img/docs/2009-11-19-233059Jack.jpg

)

Those are the ids of the people I want associated with this document. However, nothing is transferred to documents_people. What have I done wrong? cakephp save has-and-belongs-to-many
  |
  this question edited Dec 25 '15 at 13:24 Brian Tompsett - 汤莱恩 4,008 13 36 83 asked Nov 19 '09 at 23:36 Frank Luke 887 2 15 30



 |  1 Answers

up vote 7 down vote ---Accepted---Accepted---Accepted---

Perhaps your $this->data array should have a 'Person' section, not a plural 'People' Have you tried... echo $form->input('Person'.....


  |
  this answer answered Nov 21 '09 at 3:24 Simon East 29.1k 10 94 92 So simple, but correct. –  Frank Luke Nov 23 '09 at 15:57



 | 

Recommend:has and belongs to many - Cakephp 2.2.3 habtm saving to intermediary table

everything. I double checked it all and its all working (add, edit, delete). The one thing I cannot get working is saving to the intermediary table between the users table and a websites table. The intermediary table is user_websites. The u

up vote 1 down vote favorite 2 I have two models related HABTM (documents and people). class Person extends AppModel {

var $name = 'Person';

var $hasAndBelongsToMany =

------splitte line----------------------------