Re: How to update multiple table data using saveall
Thank you! If I assign an id correctly, cake updates as I wanted! On Mar 11, 12:23 am, josu jauregui wrote: > Hi! You may to assign an id to the object; if the object doesn´t have an id, > cakephp creates a new record. Try this: > > function edit($id = null) { > if (!empty($this->data)) { > * $this->Book->id=$id;* > $this->Book->saveall($this-> > > > > > data); > > $this->redirect(array('action' => 'index')); > > } > > if (empty($this->data)) { > > $this->data = $this->Book->read(null, $id); > > } > > } > > I hope it can help you. Bye! > > 2010/3/10 newtocake > > > 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] > > > 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 sitehttp://cakeqs.organd 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 cake-php@googlegroups.com > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.comFor > > 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to update multiple table data using saveall
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 jeremybu...@me.com 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] > > 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 cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: How to update multiple table data using saveall
Hi! You may to assign an id to the object; if the object doesn´t have an id, cakephp creates a new record. Try this: function edit($id = null) { if (!empty($this->data)) { * $this->Book->id=$id;* $this->Book->saveall($this-> > > data); >$this->redirect(array('action' => 'index')); >} >if (empty($this->data)) { >$this->data = $this->Book->read(null, $id); >} >} I hope it can help you. Bye! 2010/3/10 newtocake > 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] > > 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 cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.comFor > 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
How to update multiple table data using saveall
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] 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en