Just fixed it.

I was passing the $id to the action, but I hadn't added the hidden id
fields to the form, so that each element knew what to update.

So the two things I had to add were:

- hidden id field for the Album
- hidden id field for each track that was already part of the Album
(i.e. in my foreach)

This also allows you to add new tracks to existing albums without it
creating a new album.  I can give some more details if needed.

On Oct 11, 7:26 pm, ajoberstar <[email protected]> wrote:
> So I've got aformthat's got fields for both themodel(Album) and
> its associated (hasMany)model(Track).  Anytime I use theeditform
> it does anadd.  I'm assuming this is an issue with how my data is
> being passed to saveAll() but I can't figure it out (I'm pretty new to
> CakePHP).
>
> Here's what myeditaction looks like in the AlbumsController.
>
> --------------------------------------------------------------------------- 
> -----------------------------------------
>
> functionedit($id = null)
> {
>         $this->Album->id = $id;
>
>         if (empty($this->data))
>                 $this->data = $this->Album->read();
>         else if ($this->Album->saveAll($this->data, array('validate' =>
> 'first')))
>                 $this->redirect(array('action' => 'index'));
>         else
>                 $this->redirect($this-referer());
>
> }
>
> --------------------------------------------------------------------------- 
> -----------------------------------------
>
> Any help would be much appreciated.
--~--~---------~--~----~------------~-------~--~----~
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