I have the following two tables:
create table teams (
id int not null auto_increment,
short_name varchar(12) not null,
long_name varchar(50) not null,
logo varchar(20) not null,
primary key (id)
);
create table rounds (
id int not null auto_increment,
home_team_id int not null,
away_team_id int not null,
round tinyint(4) not null,
home_team_score tinyint(8) not null,
away_team_score tinyint(8) not null,
constraint fk_home_teams foreign key (home_team_id) references
teams(id),
constraint fk_away_teams foreign key (away_team_id) references
teams(id),
primary key (id)
);
And I need to be able to access this data through a join, ie I want to
be able to do things like:
@round1 = Round.get_round(1)
And then be able to access
@roind1.home_team_score
@round1.home_team.short_name
@round1.away_team.short_name
etc
But I just can’t figure out how to use belongs_to and has_many to get
this relationship going because i’m using TWO FOREIGN KEYS to join the
SAME TABLE…
I am very new to rails, sorry if this is a stupid question, but any help
someone could provide would be greatly appreciated.
Chris.