File size: 432 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Comment < ApplicationRecord
  validates :author_id, :post_id, :body, presence: true

  belongs_to :author,
    foreign_key: :author_id,
    class_name: :User
  
  belongs_to :post,
    foreign_key: :post_id,
    class_name: :Post
  
  belongs_to :parent_comment,
    foreign_key: :parent_id,
    class_name: :Comment,
    optional: true
  
  has_many :child_comments,
    foreign_key: :parent_id,
    class_name: :Comment
end