Structure movie lists
I'm trying to set up a proper database-design, but I'm stuck.
Here is what I'm trying to save.Every user can define a vote history list from imdb looking like this.
Two users can define the same list.
First I want to be able to save each list as an imdb_vote_history_list
- list.
class ImdbVoteHistoryList < ActiveRecord::Base
has_and_belongs_to_many :vote_history_list
has_and_belongs_to_many :movies
# Fields
# id (Integer) - defined by the user
end
Each list should be unique and is being defined by it's ID (given in the link). Each list has and belongs to many m开发者_如何学编程ovies, as in the code above.
Each user should be able to pick a name for every list. So instead of saying
Each imdb_vote_history_list belongs_to user
I create a new relation called vote_history_list
.
class VoteHistoryList < ActiveRecord::Base
has_and_belongs_to_many :imdb_vote_history_lists
belongs_to :user
# Fields
# name (String)
end
Here the user can pick any name for the list, without interference with other user's names.
Is this a good way to store the data?
From the theoretical database design view this is the right approach. For example the entity relationship model describes it this way. You can have relationships between entities and attributes at those relationships. If you map those to a relational model (database tables) you get a table for the relationship containing references to both entites and all additional information. This is what theory can tell us about it :)
精彩评论