debug($this->data) and check that the primary keys (id) have values in them. If 
they do, Cake should update those rows. If they are blank, Cake assumes you 
want to add new ones. When you create the form, populate the id field (hidden, 
I guess) with the value from the $this->data array.

Jeremy Burns
[email protected]


On 10 Mar 2010, at 12:18, newtocake wrote:

> Hi, I want to update data of several tables when I edit them, but
> somehow, it creates new records. :(   Does somebody have any idea?
> 
> books table   [id, name, user_id]
> users table [id, name, password]
> comments table [id, comment, user_id, book_id]
> 
> [books_controller]
> 
>        var $uses = array('Book','Comment');
> 
>       function edit($id = null) {
>               if (!empty($this->data)) {
>                       $this->Book->saveall($this->data);
>                       $this->redirect(array('action' => 'index'));
>               }
>               if (empty($this->data)) {
>                       $this->data = $this->Book->read(null, $id);
>               }
>       }
> 
> [book model]
> 
>        var $belongsTo = 'User';
>        var $hasOne = 'Comment';
> 
> [index view]
> 
> <?php echo $html->link('Edit',array('action' => 'edit', $value['Book']
> ['id'])); ?>
> 
> [edit view]
> 
> echo $form->create('Book');
> echo $form->input('id');
> echo $form->input('Book.name');
> echo $form->input('User.name');
> echo $form->input('Comment.comment');
> echo $form->end('Submit');
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to