Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinrhode2/0afb9a5207ff67615832 to your computer and use it in GitHub Desktop.
Save devinrhode2/0afb9a5207ff67615832 to your computer and use it in GitHub Desktop.

Typical has_many :items, :through => :list_items A MediaItem is a book, audiobook, or video, or any other generic MediaItem A MediaList can be one of two things: a category and a users personal library.

By allowing a MediaItem to know about how many lists it is on, you can track usage and popularity of that MediaItem and show 'tags' representing each category it's in.. so but I think category and a users media collection should both be unique and inherit from MediaList.. could this be polymorphism? So there are 2 types of MediaLists,

# app/models/media_list.rb
class MediaList < ActiveRecord::Base
  has_many :media_list_items
  has_many :media_items, :through => :media_list_items
end

# app/models/media_item.rb
class MediaItem < ActiveRecord::Base
  has_many :media_list_items
  has_many :media_lists, :through => :media_list_items
end

# app/models/media_list_items.rb
class MediaListItems < ActiveRecord::Base
  belongs_to :media_list
  belongs_to :media_items
end

Also, say you wanted to layer in users, and they can have a personal library of items. Would this be a User has_many :media_list_items and has_many :media_items, :through => :media_list_items?

Should User only have_one MediaList?

Lastly, would it be smart or foolish to just say a User has_one :media_list, representing their library as it's own category? Would you want to make category polymorphic maybe?

Let's say you want to layer in Users.

I think this is what I should do: class Items, class ItemList, category is an ItemList, and a users personal library is an ItemList

@devinrhode2
Copy link
Author

Can't have 2 MediaLis
Each MediaItem can only be added to a MediaList once..
Each MediaItem in a MediaList has to have a unique primary key. Perhaps, the primary key of a MediaListItem should be the same as a MediaItem?

Maybe a users personal collection shouldn't be a MediaList along with the Categories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment