I’m still learning how to design databases for my applications and need some help organizing the database for a Movie Critic application.
A critic has many comments and a comment can only belong to one critic. Do I need a link table?
My understanding is the following:
Comment Table
- id
- comment
- critic_id
Critic Table
- id
- first_name
- last_name
I understand how to link the Comment to the critic through the critic_id. However, a critic can have multiple comments and I’m confused as how to design this into the database. Obviously a Critic cannot have multiple Comments in the same database row so my assumption is that I need some sort of link table.
I’m using rails and could really benefit from details on how to properly set up the relationships in the model (ex: has_many, belongs_to, etc.)
Since you have a one-to-many relationship, your design is fine. Multiple comments of the same critic will have multiple rows in
Commenttable, each with its ownidbut sharing the samecritic_id.You only need to consider whether to keep the non-identifying relationship that you have now or perhaps use an identifying relationship instead.
Only if you had a many-to-many relationship would you need a link (aka. junction) table.