gpt4 book ai didi

ruby-on-rails - 我可以将 Rails 属性命名为 "attribute?"

转载 作者:行者123 更新时间:2023-12-04 03:34:58 24 4
gpt4 key购买 nike

我有一个在模型之间设置的多态表,我们称它为文档,以及它具有的许多属性。所以我有一个 DocumentRelationship 模型,我想在此迁移中写入多态属性名称为“attribute”。我将在 DocumentRelationship 的迁移中添加 EG:

 t.integer :attribute_id
t.string :attribute_type

然后,在文档模型中我会说:

 has_many :attributes, :polymorphic => true

has_many :authors, :through => :attributes, :source_type => "Author"

或者类似的东西。

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

谢谢!

最佳答案

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

请参阅以下部分:已报告引起麻烦的其他名称:

attributes – if you have a has_many called attributes, you can’t access to your object attributes anymore; only the associated objects

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

关于ruby-on-rails - 我可以将 Rails 属性命名为 "attribute?",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11460801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com