I'm using RoR for the frontend of a db that stores info about a game so as to make league statistics and the like available. This is being built to replace a pre-existing PHP frontend, although the database is also being redesigned to ease the transition.
Lets make a few simplified tables that are indicative of my question:
So to quickly summarize what these tables are: players and events are self explanatory. The event_players table lets us know what players were in the game when an event happened. The table points is one of several sorts of events.Code:create table players ( id int not null auto_increment, name varchar(100) not null, primary key (id) ); create table events ( id int not null auto_increment, happened_on datetime not null, primary key (id) ); create table event_players ( id int not null auto_increment, event_id int not null, player_id int not null, foreign key (event_id) references events(id), foreign key (player_id) references players(id), primary key (id) ); create table points ( id int not null auto_increment, event_id int not null, foreign key (event_id) references events(id), primary key (id) );
Now lets say I wanted to create a controller that output a list of all the players with the points they were in the game for. (Lets also assume that there are many other events in the event_players table, so you can't just count their appearances there).
My question regards the Models and Controllers needed for this system, and moving past Active Record and the scaffold...
Example Output:What are the issues at hand, here? How does one cope with that slightly more complex table relationship? I own the Agile Webdev with Rails book, but have not yet come across the info I'm looking for in regards to this. Can anyone direct me to a specific chapter?Code:Player 1 15 Player 2 12 Player 3 4 Player 4 1 Player 5 0





Bookmarks