On 4/25/06, Dick D. [email protected] wrote:
throwing all results into a variable, with no redundant info.
above?
no, you should keep the tables separate, to prevent redundancy. ie, if
you
use one table such as Music, it may look like this:
Table Music:
id | band | album | label
1, band1, album_a1, label1
2, band1, album_a2, label1
3, band1, album_a3, label1
4, band2, album_b1, label1
5, band2, album_b2, label2
6, band2, album_b2, label2
notice that band1 is repeated and label1 is repeated quite a few times.
Also, if you wanted to change the name of label1 to “Label 1”, you may
have
to update thousands of rows (depending upon how large your table is).
If
you keep them separate, the schema would look like the following:
bands: (I would probably rename this table to ‘artists’)
id | band_name |
1, band1
2, band2
albums
id | album_name | band_id
1, album_a1, 1
2, album_a2, 1
3, album_a3, 1
4, album_b1, 2
5, album_b2, 2
labels
id | label_name
1, label1
2, label2
bands_labels (join table)
band_id | label_id
1,1
2,1
2,2
and your models would look like:
band.rb
has_many :albums
has_and_belongs_to_many: labels (since a band can switch from one label
to
another during their lifetime)
album.rb
belongs_to: band
labels.rb
has_and_belongs_to_many :bands
hopefully this will help you get started.
Mike