STI, has many, and Controllers

Hi,

I’m trying to change an app I have that right now has this relationship:

Team has many Matches

I also have the appropriate Team and Match controllers, and routes:

map.resources :matches
map.resources :teams, :has_many => :matches

I need to add two different types of matches - qualifications and
finals, so I thought STI would
be helpful. So I set up:

class Match < ActiveRecord::Base
class Qualification < Match
belongs to team
class Final < Match
belongs to team

and change the Team model to have:

has_many :qualifications
has_many :finals

I added the “type” column to the matches table to make the magic work.
Now, through the console to
do some testing/investigation, I am able to add qualifications and
finals to a team.

Now I’m trying to modify the controllers and views to be able to add a
new qualification or final
match to a team. Do I now have to add two new controllers and pretty
much duplicate the Match
controller in each? To enter match data for a team, I created a link
using:

new_team_match_path(team)

I think I would need to change my routes to include:

map.resources :matches
map.resources :qualifications
map.resources :finals

map.resources :teams, :has_many => :qualifications
map.resources :teams, :has_many => :finals

Now I’m not so sure this is the way to go. Any hints or comments would
be extremely helpful!

Thanks

John T. wrote:

Hi,

I’m trying to change an app I have that right now has this relationship:

Team has many Matches

I also have the appropriate Team and Match controllers, and routes:

map.resources :matches
map.resources :teams, :has_many => :matches

I need to add two different types of matches - qualifications and
finals, so I thought STI would
be helpful.

Well, I think I’m just going to add a match_type field to the matches
model/table and just add the right stuff to make that work. Trying to
figure out the routes and controllers just isn’t working.

thanks anyway.