specs: PHP 5 with mySQL built on top of Codeigniter Framework.
I have a database table called game
and then sport specific tables like soccerGame
and footballGame
. these sport specific tables have a gameId
field linking back to the game
table. I have corresponding classes game
and soccerGame
/footballGame
, which both extend game
.
When I look up game information to display to the user, I'm having trouble figuring out how to dynamically link the two tables. i'm curious if it's possible to get all the information with with one query. The problem is, I need to query the game
table first to figure out the sport name.
if that's not possible, my next thought is to do it with two queries. have my game_model
query the game table, then based off the sport name, call the appropriate sport specific model (i.e. soccer_game_model
) and get the sport specific info.
I would also pass the game
object into the soccer_model
, and the soccer_model
would use that object to build me a soccerGame
object. this seems a little silly to me because i'm building the parent object and then giving it to the extending class to make a whole new object?
thoughts?
thanks for the help.
EDIT:
game table
gameId
sport (soccer, basketball, football, etc)
date
other data
soccerGame table
soccerGameId
gameId
soccer specific information
footballGame table
footballGameId
gameId
football specific information
and so on for other sports
So I need to know what the sport is before I can decide which sport specific table I need to pull info from.
UPDATE:
Thanks all for the input. It seems like dynamic SQL is only possible through stored procedures, something I'm not well versed on right now. And even with them it's still a little messy. Right now I will go the two query route, one to get the sport name, and then a switch to get the right model.
From the PHP side of things now, it seems a little silly to get a game
object, pass it to, say, my soccer_game_model
, and then have that return me a soccer_game
object, which is a child of the original game
. Is that how it has to be done? or am I missing something from an OO perspective here?