I have the following function set up in my GenresController. This
function is called when a user is viewing a Game and wants to add a
new genre to the DB and associate it with the game currently being
viewed.

The Game and Genre models share a HABTM relationship...I'm not having
any problems adding new genre into the Genres table, however I can't
figure out how to also add it into the HABTM relationship table
(gamesgenres).

Models:
Games
Genres
GamesGenres

Do I need to create a controller/model for the gamesgenres table and
then pass it $this->data and $id? ($id is the game ID).

function addGenreToGame ($id = null) {
  if (!empty($this->data)) {
   $this->Genre->create();
   if ($this->Genre->save($this->data)) {
    /*the new genre is saved in genres table - but also want it to
insert the genre id and game id (which is from $id) into the
gamesgenres HABTM relationship table. */
    $this->data['g
    $this->redirect(array('controller' => 'games', 'action' => 'view/'.
$id));

   } else {

   }
  }
  $this->set('genredata', $this->Genre->Game->find());
  $this->render(addGenreToGame ,'ajax');
 }

Thanks for the help!
--~--~---------~--~----~------------~-------~--~----~
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