Re: How do I save related model data
I tried that, but that didn't work either. Another thing I did was to make sure I assigned the foreign key to the data like this so the todo data has a task_id, but that just creates a new db row. $this-data['Todo']['task_id'] = $this-data['Task']['id']; On Feb 24, 11:37 pm, mscdex msc...@gmail.com wrote: On Feb 25, 2:21 am, Dhana sldh...@gmail.com wrote: Here's a snippet of the save code I am calling. if($this-Task-saveAll($this-data['Task'])){ $this-Session-setFlash('The task has been updated', 'default', array('class' = 'information')); $this-redirect(array('action' = 'show', $id)); } I think you may want: if($this-Task-saveAll($this-data)){ instead of: if($this-Task-saveAll($this-data['Task'])){ The latter appears to be just providing saveAll with just your Task information and thus is excluding your array of Todo items that came from the form. --~--~-~--~~~---~--~~ 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 do I save related model data
I tried the one below, but the todos still don't get updated. I tried a variation where I did this to make sure the foreign id(task_id) is added, but that just creates a new row instead of updating the row. $this-data['Todo']['task_id'] = $this-data['Task']['id']; On Feb 24, 11:37 pm, mscdex msc...@gmail.com wrote: On Feb 25, 2:21 am, Dhana sldh...@gmail.com wrote: Here's a snippet of the save code I am calling. if($this-Task-saveAll($this-data['Task'])){ $this-Session-setFlash('The task has been updated', 'default', array('class' = 'information')); $this-redirect(array('action' = 'show', $id)); } I think you may want: if($this-Task-saveAll($this-data)){ instead of: if($this-Task-saveAll($this-data['Task'])){ The latter appears to be just providing saveAll with just your Task information and thus is excluding your array of Todo items that came from the form. --~--~-~--~~~---~--~~ 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 do I save related model data
Something else I noticed is that your Todo text field generation code seems a bit off. You mention you want to be saving the Todo titles but your form field is the Todo's ID field filled in with the title data. Also, I haven't tested this yet but you may have to supply the ID for each Todo as hidden form elements. So the modified loop might look like this: ?php $i = 0; foreach($task['Todo'] as $todo): ? li ?php e($form-hidden(Todo.$i.id, array('value' = $todo['id']))); ? ?php e($form-text(Todo.$i.title, array('value' = $todo['title'], 'class' = 'long'))); ? /li ?php $i++; endforeach; ? --~--~-~--~~~---~--~~ 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 do I save related model data
I have a Task model which has many todos. I have a form that edits both the title of the todo and any number of the todos (if the task has any) in one form. The form as you can see below submits to the task edit action. But when I submit the form, only the title of the task is updated, but not the titles of the todos. Am I supposed to be handling the save of the todos myself in the edit action? The association are already set in the model, such $belongsTo and $hasMany. Any ideas on what I should do here? Here's my code for the form. e($form-create('Task', array('controller' = 'task', 'action' = edit/{$task['Task']['id']}, 'class' = 'form'))); e($form-hidden('Task.id', array('value' = $task['Task']['id']))); e($form-text('Task.title', array('value' = $task['Task']['title'], 'class' = 'long'))); ?php foreach($task['Todo'] as $todo): ? li ?php e($form-text({$todo['id']}.Todo.id, array('value' = $todo['title'], 'class' = 'long'))); ? /li ?php endforeach; ? e($form-submit('Edit')); e($form-end()); Here's a snippet of the save code I am calling. if($this-Task-saveAll($this-data['Task'])){ $this-Session-setFlash('The task has been updated', 'default', array('class' = 'information')); $this-redirect(array('action' = 'show', $id)); } --~--~-~--~~~---~--~~ 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 do I save related model data
On Feb 25, 2:21 am, Dhana sldh...@gmail.com wrote: Here's a snippet of the save code I am calling. if($this-Task-saveAll($this-data['Task'])){ $this-Session-setFlash('The task has been updated', 'default', array('class' = 'information')); $this-redirect(array('action' = 'show', $id)); } I think you may want: if($this-Task-saveAll($this-data)){ instead of: if($this-Task-saveAll($this-data['Task'])){ The latter appears to be just providing saveAll with just your Task information and thus is excluding your array of Todo items that came from the form. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---