Skip to content

[JITERA] Implement Comment Model for Notes

Quy requested to merge feat/add-comments-to-notes-1737393327 into main

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

  1. Migration for Comments Table:

    • Created a migration file /db/migrate/1737393206685_create_comments_table.rb to add a comments table.
    • The table includes the following columns:
      • id: Primary key.
      • content: Text content of the comment.
      • note_id: Foreign key referencing the notes table, indexed for performance.
      • created_at and updated_at: Timestamps for record tracking.
  2. Comment Model:

    • Implemented the Comment model in /app/models/comment.rb that inherits from ApplicationRecord.
    • Defined a belongs_to association with the Note model.
    • Added validations to ensure that both content and note_id are present.
  3. Update Note Model:

    • Modified the Note model in /app/models/note.rb to include a has_many association with the Comment model.
    • Ensured that comments are dependent on the note, using dependent: :destroy to automatically remove comments when a note is deleted.

These changes collectively enhance the functionality of the notes feature by allowing users to add comments, thereby improving the overall user experience.

Merge request reports