0

我想有一个父子层次结构,并且我想在父级上有一个“series-id”的概念。

所以父级(如果你更新了它)将使旧的唯一键过期..保留系列 ID 并插入第二行。

我希望孩子们“挂断”该系列 ID,而不是唯一 ID。

您知道 BelongsTo 是否可以链接到非主键(但通过 GUID 唯一)列?

父级:UniqueId (guid)、SeriesId (guid)、名称、描述 子级:UniqueId (guid)、ParentId(始终连接到 UniqueId-Above)、名称、描述。

我知道外键关系确实应该在关系的一侧有一个“键”,但是,根据我的 GUID,它们类似于键......但不是真正的键。

这没什么大不了的,但是如果我通过更新它的元数据来“过期”父级,我想避免不得不将所有子级“复制”到父级的新副本中。

我在尝试做一些不可能发生的事情吗?

4

1 回答 1

-1

belongs_to 有一个选项可以让你指定关系:

:foreign_key
    Specify the foreign key used for the association. By default this is guessed to be the name of the association with an "_id" suffix. So a class that defines a belongs_to :person association will use "person_id" as the default :foreign_key. Similarly, belongs_to :favorite_person, :class_name => "Person" will use a foreign key of "favorite_person_id".
于 2009-11-16T21:44:11.200 回答