铁路协会,habtm? 多态性? 两个都?
在我的 Rails 应用程序中,我有三个模型:项目、博客帖子和图像。 项目和博客文章可以有许多链接的图像,并且图像可以链接到项目、博客文章或两者。
建立关联以使其在 Rails 中工作的最佳方式是什么?
In my Rails app I have three models, Projects, BlogPosts and Images. Projects and BlogPosts can have many linked images and an image can be linked to a Project, a BlogPost or both.
What is the best way of setting up the associations to make this work in Rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将 habtm 梳理成一个单独的模型类 ImageLink。 然后你会得到:
I'd tease out the habtm into a separate model class, ImageLink. Then you'd get: