Skip to content

Commit

Permalink
Associate Post and User with Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
yucao24hours committed Aug 29, 2016
1 parent 71b7692 commit 6c047a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Comment < ApplicationRecord
belongs_to :post
belongs_to :commented_by, class_name: 'User'
end
1 change: 1 addition & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Post < ApplicationRecord
belongs_to :created_by, class_name: 'User'
has_many :comments, dependent: :destroy

validates :title, presence: true

Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class User < ActiveRecord::Base
include Authenticator

has_many :posts, foreign_key: 'created_by_id'
has_many :comments, foreign_key: 'commented_by_id'

class << self
def find_or_create_from(auth)
Expand Down

0 comments on commit 6c047a3

Please sign in to comment.