-----BEGIN PGP SIGNED MESSAGE-----
[email protected] wrote:
| Let’s say that I’m trying to model a baseball Game, capturing the
| names of the home and away teams within the Game class.
| Game has both a (has_a) home_team and an away_team.
| one could write the Game class like this:
| class Game < ActiveRecord::Base
| has_a home_team_id
| has_a away_team_id
| but this necessitates 2 DB tables (home_teams and away_teams) with
| duplicated content.
| is there a simple railsy way of capturing the fact that Game has both
| a home_team and an away_team but use only 1 table (called teams)? I
| realize space is cheap these days and i shouldn’t fret about
| duplication, but perhaps there’s a simpler way.
You should fret about mormalizing your data, though.
id, home_team_id, away_team_id, score_home_team, score_away_team
home_team_id = teams.id (foreign key constraint)
away_team = teams.id (foreign key constraint)
~ I don’t need to compromise my principles, because they don’t have
slightest bearing on what happens to me anyway. – Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----