-
-
Save ingrid88/5255c04caa73c4e57e3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Comment < ActiveRecord::Base | |
validates :author_id, :post_id, :content, presence: true | |
belongs_to :author, | |
class_name: "User", | |
foreign_key: :author_id | |
belongs_to :post | |
#where primary key = value of foreign key | |
belongs_to :parent, | |
class_name: "Comment", | |
foreign_key: :parent_comment_id | |
#where their foreign key is equal to the value of the primary key (id) | |
has_many :child_comments, | |
class_name: "Comment", | |
foreign_key: :parent_comment_id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment