ActiveRecord 与复合键根本不兼容?
我一直在尝试在我正在进行的项目中使用亚音速。一切进展顺利,直到我遇到带有复合主键的链接表。这是一个由它连接的两个表的主键组成的键。 Subsonic 无法识别两个按键,这是有问题的。我本来打算调整亚音速以支持复合键,但我停了下来,虽然“也许这是有原因的”。通常,活动记录依赖于每个记录的单个主键字段,即使在链接表中也是如此。但这有必要吗?我应该放弃该项目的活动记录还是继续修改?
I have been attempting to use subsonic for a project on which I'm working. All was going quite well until I encountered a link table with a composite primary key. That is a key made up of the primary keys of the two tables it joins. Subsonic failed to recognize both keys which was problematic. I was going to adjust subsonic to support compound keys but I stopped and though "Maybe there is a reason for this". Normally active record relies on a single primary key field for every record, even in link tables. But is this necessary? Should I just give up on active record for this project or continue with my modifications?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ruby on Rails 不支持开箱即用的模型对象中的复合主键。但是,有一些插件可以实现此目的,例如 this。
您可以在连接表上拥有复合主键,但 Rails 不会创建该主键,您必须手动创建它。
请参阅本指南。
Ruby on Rails does not support composite primary keys in model object out of the box. However, there are plugins that accomplish that, for example this.
You can have composite primary key on a join table, but Rails will not create that primary key, you have to create it manually.
See this guide.