ActiveRecord 与复合键根本不兼容?

发布于 2024-08-12 17:50:18 字数 196 浏览 2 评论 0原文

我一直在尝试在我正在进行的项目中使用亚音速。一切进展顺利,直到我遇到带有复合主键的链接表。这是一个由它连接的两个表的主键组成的键。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

︶ ̄淡然 2024-08-19 17:50:18

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文