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 bugs
bugs HABTM users
Now I write a method in Bugs controller which name add() just like below
function 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>
<?php
echo $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
No comments:
Post a Comment