问题描述
我想使用名为 type
的列而不调用单表继承 (STI) - 我只希望 type
成为一个包含 String 的普通列代码>.
I want to use a column called type
without invoking Single Table Inheritance (STI) - I just want type
to be a normal column that holds a String
.
如何在没有 Rails 期望我有单表继承并抛出异常的情况下执行此操作 单表继承机制无法定位子类...引发此错误是因为列类型"保留用于在继承的情况下存储类.
?
How can I do this without having Rails expecting me to have single table inheritance and throwing an exception of The single-table inheritance mechanism failed to locate the subclass...This error is raised because the column 'type' is reserved for storing the class in case of inheritance.
?
关于如何做到这一点的任何想法?
Any ideas on how to do this?
推荐答案
In Rails 3.1 set_inheritance_column
已弃用,你也可以使用 nil
作为名称,像这样:
In Rails 3.1 set_inheritance_column
is deprecated, also you can just use nil
as a name, like this:
class Pancakes < ActiveRecord::Base
self.inheritance_column = nil
#...
end
这篇关于Rails——使用没有 STI 的类型列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!