所以说我有一个相当典型的博客。
A post belongs to a user.
A user has many posts.
A post has many comments.
A comment belongs to a post.
A comment belongs to a user.
我知道,当我创建帖子时,我可以执行以下操作:
@post = @user.posts.build(subject: "Lorem ipsum", content: "Lorem ipsum") }
但我不确定我会如何处理评论,因为它与帖子和用户都相关。为简单起见,假设评论只有三个字段,内容、user_id 和 post_id。我还能以某种方式使用构建方法吗?任何指针将不胜感激。