模型是否必须链接到另一个模型,或者是否可以链接到基于同一模型的 table?

Does a model have to be linked to another model or can it be linked to a table based on the same model?

我正尝试在 RoR 上调试大型应用程序 运行。在我的模型中 Text 我有这样的关系:

has_many :copies, :foreign_key => :original_id

这是否意味着我的应用程序中必须有另一个名为 Copie 的模型(应该是 Copy...),它通过 foreign_key linked 或者它可能只是一个link 到另一个使用相同模型的 table Text?

在大多数情况下,是的。会有一个 Copy 模型。不过,您可以使用 class_name 选项

将其指向不同的模型

通常,如果它引用了不同的 table,就会使用 class_name 关键字。例如:has_many :copies, :class_name => 'YourOtherModel', :foreign_key => :original_id

按照惯例,Rails假定用于保存其他模型外键的列是该模型的名称加上后缀 _id。

Rails 确实为您提供了直接设置 :foreign_key 选项的能力:

查看文档 here

您还可以设计一个数据模型使其与自身相关:

查看文档 here

我希望这能为您提供一些深入调查的见解