[JITERA] Implement Comment Model for Notes
Created by: akuita
Overview
This pull request introduces a new Comment model that is associated with the existing Note model. This enhancement allows each note to have multiple comments, facilitating better user interaction and feedback.
Changes Made
-
Migration for Comments Table:
- Created a migration file
/db/migrate/1737393206685_create_comments_table.rbto add acommentstable. - The table includes the following columns:
-
id: Primary key. -
content: Text content of the comment. -
note_id: Foreign key referencing thenotestable, indexed for performance. -
created_atandupdated_at: Timestamps for record tracking.
-
- Created a migration file
-
Comment Model:
- Implemented the
Commentmodel in/app/models/comment.rbthat inherits fromApplicationRecord. - Defined a
belongs_toassociation with theNotemodel. - Added validations to ensure that both
contentandnote_idare present.
- Implemented the
-
Update Note Model:
- Modified the
Notemodel in/app/models/note.rbto include ahas_manyassociation with theCommentmodel. - Ensured that comments are dependent on the note, using
dependent: :destroyto automatically remove comments when a note is deleted.
- Modified the
These changes collectively enhance the functionality of the notes feature by allowing users to add comments, thereby improving the overall user experience.