Answer the question
In order to leave comments, you need to log in
How to make the right association for likes?
Hello.
I am making a rating system on the site and the urgent question arose of how to properly implement it.
Given:
User can like a comment, post, etc.
How models look like,
User
has_many :likes
has_many :comments, through: :likes
Like
belongs_to :user
belongs_to :comment
Comment
has_many :likes
Likes.new(comment_id: nil, post_id: 1, user_id: 1)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question