我有一个在模型之间设置的多态表,我们称之为文档,以及它所具有的许多属性。所以我有一个 DocumentRelationship 模型,我想在这个迁移中写下多态属性名称将是“属性”。EG 在 DocumentRelationship 的迁移中我要添加:
t.integer :attribute_id
t.string :attribute_type
然后,在 Document 模型中,我会说:
has_many :attributes, :polymorphic => true
has_many :authors, :through => :attributes, :source_type => "Author"
或类似的东西。
我可以将此字段命名为“属性”吗?我知道您不能将多态字段命名为“对象”;这会导致错误..
谢谢!