Skip to content

Instantly share code, notes, and snippets.

@ingrid88
Created September 29, 2015 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ingrid88/5255c04caa73c4e57e3e to your computer and use it in GitHub Desktop.
Save ingrid88/5255c04caa73c4e57e3e to your computer and use it in GitHub Desktop.
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