spectra-music / spectra

A web-based personal music library manager
13 stars 1 forks source link

Rework the Track Album Artist relationship #13

Closed kristenmills closed 10 years ago

kristenmills commented 10 years ago

So here's the "more coherent" (sort of) version of everything a rambled on about on gitter for awhile.

So here's how Artist, Track, and Album are set up now.

class Track 
  belongs_to :album
  belongs_to :artist
end

class Album
  has_many :tracks
  belongs_to :artists
end

class Artist
   has_many :tracks
   has_many :albums
end

Problem 1. An album should also be able to have many artists. That's what a compilation is. And instead of having a flag for compilation, it should just be an album with multiple artists. But that's not a huge problem, it will be conveniently fixed in proposed suggestion to fix problem 2.

Problem 2. Situation: An album A by artist B is made up of tracks by artists C and D who are not associated with the album at all. Conveniently are controllers are setup so this is all fine and dandy when we go to the three different album pages for each of the three artists. (which is not a good thing, but we can fix that when we fix this.). And they will all just show Artist B as the artist. But why is artist B the artist when he has no tracks on the album? That's a sign our schema isn't set up right.

The problem is that our relationships are disconnected. Albums is related Tracks and Artists are related to Tracks and Artists are related to Albums. The relationship between Artists and Albums have nothing to do with the other two relationships when it should. At the end of the day, the only thing that should determine whether an Artist and an Album are related is whether an Artist has tracks on this albums. And that's an easy relationship to model with has_many :through. So I propose we change our relationship to this:

class Track 
  belongs_to :album
  belongs_to :artist
end

class Album
  has_many :tracks
  has_many :artists, through: :tracks
end

class Artist
   has_many :tracks
   has_many :albums, through: :tracks
end

So in this relationship, Track is in the center of it all. We don't have to deal with the relationship between album and artist anymore. The album's artists will be the artists of its tracks and an artist's albums with be albums that they have tracks on. And it also happens to fix the fact that an Album should be able to have many artists.

I hope this makes sense. And if anyone else has other ideas for modeling this relationship, we can discuss that here.

kristenmills commented 10 years ago

Per the gitter discussion, we've decided that the model is staying the same.

Instead the views are changing. The changes to the views will be documented in the wiki.