I have users, posts, and comments. Posts belong to users. Users have many posts.
Now where I’m confused is that users are supposed to be able to comment on others’ posts.
How do I set up this association?
Should I write users have many comments, posts have many comments, comments belong to posts and users? or user has many comments through posts?
Also what columns should the model table have? Does it need user_id, post_id, content?
You are correct the first time.
Users have many comments. Posts have many comments. Comment belongs to User. Comment belongs to Post.
The comments table should have user_id and post_id.
So
user.commentswill be comments that a user has made.post.commentswill be comments on that post.This is an association to say “This user commented on this post.”