type 字段在 Rails 中默认使用来做 STI(single-table inheritance),
当 type 作为普通字段来使用时,可以把SIT的列设置成别的列名(比如不存在的某个列)。
文档在这里
http://api.rubyonrails.org/classes/ActiveRecord/ModelSchema/ClassMethods.html#method-i-inheritance_column,
使用下面的方法就是设置 STI 使用的列名,默认是‘type',既然不想使用 STI了,可以设置一个不太可能和以后的列名冲突的名字,比如使用 ’_disable‘。
比如可以在 Model 中设置为
self.inheritance_column = '_disable'
Defines the name of the table column which will store the class name on single-table inheritance situations.
The default inheritance column name is type
, which means it's a reserved word inside Active Record. To be able to use single-table inheritance with another column name, or to use the column type
in your own model for something else, you can set inheritance_column
:
self.inheritance_column = 'zoink'