Sometimes more than one artist will be on a song. For example, Jay-z’s new song “A Star is Born” features the artist Cole, and thus would be listed as “Jay-z (featuring Cole) – A Star is Born” in a catalog. My question is how to model this in my database.
Right now it’s pretty simple: every song belongs_to :artist and every artist has_many :songs. I want to change this so that songs have many artists, with one artist specified as “primary” — i.e., if A, B, and C are all associated with a given song and A is primary, the artist of that song will be displayed as “A (featuring B and C)”.
Here’s what I’m thinking:
Song:
has_many :artists, :through => :performances
Artist:
has_many :songs, :through => :performances
where the performance model would have a single field for primary?, designating whether a given performance was the “primary” performance on the song, meaning that the artist associated with that performance is the primary artist on the song.
Does this approach make sense?
Yes. You nailed it.