saveAll() does work with HABTM.  saveAll() does not however work when
your data arrays are not formatted the way it likes them.  Which seems
to be the case here.  You have the User key inside the Player key.
That is not saveAll()'s preferred diet.  It likes it habtm at the same
depth as the related model.  Much like save().

-Mark

On Feb 25, 10:20 am, spazard1 <spaza...@gmail.com> wrote:
> saveAll is supposed to work with HABTM though.  I'm trying to save
> multiple Player at the same time, all of which should also save an
> associated User.  I'm thinking I just setup the data array incorrectly
> or something like that, which is causing it not to save.
>
> On Feb 25, 4:58 am, luke BAKING barker <lukebar...@gmail.com> wrote:
>
> > hi
>
> > use save() not saveAll with HABTM
>
> > On Feb 25, 7:01 am, spazard1 <spaza...@gmail.com> wrote:
>
> > > Hello all.
>
> > > I am running into a problem where my join tables are not being updated
> > > when I call saveAll.  I have the latest stable version of cakephp, in
> > > which this bug was fixed.
>
> > > Here is the relevant action code:
> > > //first update the ['Player'] array to replace username with ['User']
> > > ['id']
> > >          foreach ($this->data['Player'] as $key => $row) {
> > >             $this->data['Player'][$key]['campaign_id'] = $id;
> > >             if ($this->data['Player'][$key]['username'] != "") {
> > >                $this->data['Player'][$key]['User']['id'] = 
> > > $this->User->field('id', array('User.username' => 
> > > $this->data['Player'][$key]
>
> > > ['username']));
> > >             }
> > >          }
> > >         debug($this->data['Player']);
> > >          if ($this->Campaign->save($this->data)) {
> > >             if ($this->Player->saveAll($this->data['Player'])) {
> > >                $this->flash('Your campaign has been setup.', "/
> > > campaigns/run/$id");
> > >             }
> > >          }
> > >       }
>
> > > And the Player data that is in $this->data['Player'] (only showing the
> > > first)
> > > [0] => Array
> > >         (
> > >             [characterName] =>
> > >             [playerName] =>
> > >             [username] => testing
> > >             [baseExperienceSpent] =>
> > >             [overlord] => 0
> > >             [campaign_id] => 3
> > >             [User] => Array
> > >                 (
> > >                     [id] => 11
> > >                 )
> > >         )
>
> > > The way I understand it, this should cause my players_users table to
> > > have a row inserted into it.  However that is not happening.  When I
> > > do a find() on Player, it does return to me the associated Users, so
> > > I'm pretty sure the model associations are setup correctly.
>
> > > Thanks for any help you can offer.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to