Add comment model and its tests

This commit is contained in:
riggraz
2019-09-16 16:05:00 +02:00
parent b3fefe77ee
commit 3f4eba70d7
5 changed files with 94 additions and 1 deletions

8
app/models/comment.rb Normal file
View File

@@ -0,0 +1,8 @@
class Comment < ApplicationRecord
belongs_to :user
belongs_to :post
belongs_to :parent, class_name: 'Comment', optional: true
has_many :children, class_name: 'Comment', foreign_key: 'parent_id', dependent: :destroy
validates :body, presence: true, length: { minimum: 4 }
end