Thank you very much for your kindly help.
2011/3/5 Stephen <stephen@ninjacodermonkey.co.uk>
Hi There
From the cookbook:With HABTM, you need to set the ID of the associated model in your data array. We'll build a form that creates a new tag and associates it on the fly with some recipe. [1]
Try doing User.id not User.username
[1] http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM#!/view/1034/Saving-Related-Model-Data-HABTM
On 5 March 2011 07:18, Ekin Han <nbkhic007@gmail.com> wrote:Hi all,I have such a problem about HABTM.I have 3 tables, users table, bugs table and bugs_users table.The relation ship between users and bugs are just like below:users HABTM bugsbugs HABTM usersNow I write a method in Bugs controller which name add() just like belowfunction add(){if(!empty($this->data)){debug($this->data);die;$this->Bug->create();if($this->Bug->Save($this->data)){$this->Session->setFlash(__('Create Successfully', true));$this->redirect(array('action' => 'index'));} else{$this->Session->setFlash(t('Can Not create bug', true));}}}And the add.ctp is just like below:<h3>Create Bug</h3><?phpecho $form->create('Bug', array('action' => 'add'));echo $form->input('title');echo $form->input('description');echo $form->input('User.username');echo $form->end('Submit');?>I have a problem that when a new bug was add ,the table bugs_uses has nothing new in it.Shall I need to write a record to it myself? That means cake do not automaticly write a record the the relation table?--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
--
Kind Regards
Stephen
http://www.ninjacodermonkey.co.uk
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment