Skip to content

Commit

Permalink
Fix foreign key for post
Browse files Browse the repository at this point in the history
  • Loading branch information
TruongNM committed Nov 24, 2018
1 parent 637551e commit 981d679
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@

# Ignore application configuration
/config/application.yml
public/*
6 changes: 3 additions & 3 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Post < ApplicationRecord
belongs_to :user
has_many :photos, dependent: :destroy
has_many :likes, -> {order(:created_at => :desc)}
has_many :comments, -> {order(:created_at => :desc)}
has_many :bookmarks
has_many :likes, -> {order(:created_at => :desc)}, dependent: :destroy
has_many :comments, -> {order(:created_at => :desc)}, dependent: :destroy
has_many :bookmarks, dependent: :destroy

def is_belongs_to? user
Post.find_by(user_id: user.id, id: id)
Expand Down

0 comments on commit 981d679

Please sign in to comment.