Mr X likes only one post made by Mr Y
How can I create a relationship between Mr X and Mr Y to see the Mr Y's posts? (to see the suggested posts)
user.rb
has_many :posts
has_many :liked_posts, through: :liked, source: :post
post.rb
def liked_by?(user)
likes.where(user: user).any?
end
likes.rb
# id :integer not null, primary key
# user_id :integer not null
# like_id :integer not null
Should I use uniq ?
Aucun commentaire:
Enregistrer un commentaire