3

我有一个在模型之间设置的多态表,我们称之为文档,以及它所具有的许多属性。所以我有一个 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"

或类似的东西。

我可以将此字段命名为“属性”吗?我知道您不能将多态字段命名为“对象”;这会导致错误..

谢谢!

4

1 回答 1

2

http://oldwiki.rubyonrails.org/rails/pages/ReservedWords

请参阅以下部分:据报道会引起麻烦的其他名称:

attributes – 如果你有一个 has_many 调用的属性,你不能再访问你的对象属性;只有关联的对象

更新:此链接包含更多详细信息https://github.com/walterdavis/railsready/wiki还可以查看他的具有搜索功能的 heroku 应用程序http://reservedwords.herokuapp.com/

于 2012-07-12T21:20:47.527 回答