Re: saveAll not saving habtm with build 8004

2009-02-26 Thread spazard1

I should mention that in my data I want User[0] to be associated with
Player[0], and so on.

On Feb 26, 9:55 am, spazard1  wrote:
> I have my data in this format now (below).  How do I call save/saveall
> to update the Campaign, Player and the habtm players_users?
>
> I have tried this:
> if ($this->Campaign->save($this->data)) {
>       if ($this->Campaign->Player->saveAll($this->data)) {
>             $this->flash('Your campaign has been setup.', "/campaigns/
> run/$id");
>        }}
>
> This only saves the first player, and does not save any of the habtm
> with user.
>
> if ($this->Campaign->save($this->data)) {
>       if ($this->Player->saveAll($this->data['Player'])) {
>             $this->flash('Your campaign has been setup.', "/campaigns/
> run/$id");
>        }}
>
> This saves all the players, but does not save the habtm with user.
>
> Thanks again for the help.
>
> Array
> (
>     [Campaign] => Array
>         (
>             [id] => 3
>             [baseHeroConquest] =>
>             [baseOverlordConquest] =>
>         )
>     [Player] => Array
>         (
>             [0] => Array
>                 (
>                     [characterName] =>
>                     [playerName] =>
>                     [username] => testing
>                     [baseExperienceSpent] =>
>                     [overlord] => 0
>                     [campaign_id] => 3
>                 )
>
>             [1] => Array
>                 (
>                     [characterName] =>
>                     [playerName] =>
>                     [username] => testing2
>                     [baseExperienceSpent] =>
>                     [overlord] => 0
>                     [campaign_id] => 3
>                 )
>
>             [2] => Array
>                 (
>                     [characterName] =>
>                     [playerName] =>
>                     [username] =>
>                     [baseExperienceSpent] =>
>                     [overlord] => 0
>                     [campaign_id] => 3
>                 )
>
>             [3] => Array
>                 (
>                     [characterName] =>
>                     [playerName] =>
>                     [username] =>
>                     [baseExperienceSpent] =>
>                     [overlord] => 0
>                     [campaign_id] => 3
>                 )
>
>             [5] => Array
>                 (
>                     [characterName] => The Titan
>                     [playerName] =>
>                     [username] =>
>                     [baseExperienceSpent] =>
>                     [overlord] => 1
>                     [campaign_id] => 3
>                 )
>
>         )
>     [User] => Array
>         (
>             [0] => Array
>                 (
>                     [id] => 11
>                 )
>             [1] => Array
>                 (
>                     [id] => 12
>                 )
>         )
> )
>
> On Feb 25, 1:14 pm, mark_story  wrote:
>
> > 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  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  wrote:
>
> > > > hi
>
> > > > use save() not saveAll with HABTM
>
> > > > On Feb 25, 7:01 am, spazard1  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");
> > > > >             }
> > > > >          }
> > > > >       }
>
> > 

Re: saveAll not saving habtm with build 8004

2009-02-26 Thread spazard1

I have my data in this format now (below).  How do I call save/saveall
to update the Campaign, Player and the habtm players_users?

I have tried this:
if ($this->Campaign->save($this->data)) {
  if ($this->Campaign->Player->saveAll($this->data)) {
$this->flash('Your campaign has been setup.', "/campaigns/
run/$id");
   }
}
This only saves the first player, and does not save any of the habtm
with user.

if ($this->Campaign->save($this->data)) {
  if ($this->Player->saveAll($this->data['Player'])) {
$this->flash('Your campaign has been setup.', "/campaigns/
run/$id");
   }
}
This saves all the players, but does not save the habtm with user.

Thanks again for the help.


Array
(
[Campaign] => Array
(
[id] => 3
[baseHeroConquest] =>
[baseOverlordConquest] =>
)
[Player] => Array
(
[0] => Array
(
[characterName] =>
[playerName] =>
[username] => testing
[baseExperienceSpent] =>
[overlord] => 0
[campaign_id] => 3
)

[1] => Array
(
[characterName] =>
[playerName] =>
[username] => testing2
[baseExperienceSpent] =>
[overlord] => 0
[campaign_id] => 3
)

[2] => Array
(
[characterName] =>
[playerName] =>
[username] =>
[baseExperienceSpent] =>
[overlord] => 0
[campaign_id] => 3
)

[3] => Array
(
[characterName] =>
[playerName] =>
[username] =>
[baseExperienceSpent] =>
[overlord] => 0
[campaign_id] => 3
)

[5] => Array
(
[characterName] => The Titan
[playerName] =>
[username] =>
[baseExperienceSpent] =>
[overlord] => 1
[campaign_id] => 3
)

)
[User] => Array
(
[0] => Array
(
[id] => 11
)
[1] => Array
(
[id] => 12
)
)
)


On Feb 25, 1:14 pm, mark_story  wrote:
> 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  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  wrote:
>
> > > hi
>
> > > use save() not saveAll with HABTM
>
> > > On Feb 25, 7:01 am, spazard1  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]

Re: saveAll not saving habtm with build 8004

2009-02-25 Thread mark_story

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  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  wrote:
>
> > hi
>
> > use save() not saveAll with HABTM
>
> > On Feb 25, 7:01 am, spazard1  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
-~--~~~~--~~--~--~---



Re: saveAll not saving habtm with build 8004

2009-02-25 Thread spazard1

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  wrote:
> hi
>
> use save() not saveAll with HABTM
>
> On Feb 25, 7:01 am, spazard1  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
-~--~~~~--~~--~--~---



Re: saveAll not saving habtm with build 8004

2009-02-25 Thread luke BAKING barker

hi

use save() not saveAll with HABTM

On Feb 25, 7:01 am, spazard1  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
-~--~~~~--~~--~--~---



saveAll not saving habtm with build 8004

2009-02-25 Thread spazard1

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
-~--~~~~--~~--~--~---