Topic: STI, Products & Formats
I'm in a bit of a pickle with my latest project, an online record label which sells both digital and hard copies of its music, along with promotional merchandise.
Now, I'd like to use the classic relationship of :products and :carts. The problem I am facing is that the products are so radically different that I'm not sure how to build my models (or DB for that matter).
I think I am on the right track but would love some feedback on my outline:
# t.columns for products
# :name, :price, :shipping_weight
Those 3 columns are really the only commonalities shared by all products. Now onto the variations:
class MusicFormat < Product
class DigitalFormat < Product
class Format < Product
Basically what I would like is to create a select list of established formats. Music would have Vinyl LP, CD, etc.. MP3s would be available as singles, promos while accessories would have shirts, hats and whatnot.
Selecting a given format will automatically assign a price and shipping weight (if any) to a given item and save my client from headaches and errors.
I am leaning towards using one table for these format classes since they are so similar but I'm not sure .. should I go STI on this puppy using product as the parent class?
Moving on, let's take a look at the music products.
# t.columns for record_labels
# :logo, :name, :info, :email, :website
# t.columns for releases
# :music_format_id, :record_label_id, :artist, :featuring, :cover_art,
# t.columns for mp3s
# :digital_format_id, :release_id, :demo_file, :digital_download, :runtime
My biggest confusion here is in how to deal with releases, since they will all be available as individual MP3 files as well as MP3 packs...and sometimes they will also have vinyl or CD versions available. I imagine I can probably sort this out with model methods, but any advice on structure would be helpful too.
Now for the last bit:
# t.columns for accessories
# :format_id, :size, :color
Though I like to think of myself as an "advanced noob" I am pretty sure I butchered some ActiveRecord here. Feel free to provide suggestions or even yell at me if necessary