0

Here's my situation...I am making a website of games. Each games has many modes, and each game also has many puzzles. For example, if the game is a word search game, a puzzle will be a unique grid of letters, and a mode will be how the game is scored. Perhaps in the first mode the game is timed, and in the second mode, the game is not timed. And if you keep the same mode but change the "puzzle" of the game, then the collection of letters in the word search changes,but the way the game is scored stays the same. Therefore, each game has many modes and many puzzles.

However, the best way for me to design this is really to create a HABTM table for modes and puzzles (each puzzle has many modes, each mode has many puzzles and each game has many mode_puzzles, if you will). Because that way I can say each mode_puzzle has many highscores. So the structure would be Game->Mode_Puzzle->Highscore.

However making this is really annoying because each game has hundreds of puzzles and modes are really related to the games and not the individual puzzles. It's such overkill, if I have 10 games of 100 puzzles each and 5 modes per game to create a table of 5,000 rows, when it's as simple as every mode belongs to every puzzle for each game.

So my question is, does CakePHP support an autogenerated HABTM table? Or do I have to create a table manually despite the fact that the logic of the table is so self explanatory?

Nick Manning
  • 2,828
  • 1
  • 29
  • 50
  • 1
    So are puzzles unique to a game? If so then surely you can just do Game hasMany Puzzles and Puzzles hasMany Modes No need for a HABTM relationship here? – Nick Martin Apr 30 '13 at 10:16
  • You're right but I am caching this entire structure in a threaded array, to 4 degrees: Game->Mode/Puzzle->Highscore->User. If I do Game->Puzzle->Mode->Highscore->User, then the array becomes huge. I don't really know if that's an issue or not. – Nick Manning Apr 30 '13 at 10:46
  • 1
    I dont think you necessarily need to think of it in such a rigid way. You could also relate a Highscore; belongsTo Game/Puzzle/Mode/User (all of them) and you could access a highscore; Game->Highscore or User->Highscore and see the Highscores with associated Mode/Puzzle/Users/Games? There are a lot of options, so I guess it's up to you to take the route that makes the most sense to you. – Nick Martin Apr 30 '13 at 11:08
  • That would work but I like to be rigid so that I can make huge projects and remember what is what...if I apply highscores to both games and users I might not remember that if I leave the project for 2 months and come back to it. Ya know? But maybe when I am a more experienced programmer I will be more willing to do things that make sense. – Nick Manning Apr 30 '13 at 11:47

0 Answers0