Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 Post 和 Comment 模型,现在我想创建 User 模型。用户 has_many 帖子,并且 post belongs_to 用户。当我使用生成器创建评论模型时,我使用了post:references,所以我需要手动将 user_id 列添加到 Post 模型吗?
是的。
rails generate migration AddUserIdToPosts user_id:integer
并手动将 *belongs_to user* 放入 Post 模型中。