所以,我正在使用现有的数据库迁移这个 php 站点,我无法将其更改为 Rails。有一张 table :Quotes
有一列名为 type
.每当我尝试创建此模型并设置类型时,它都会告诉我以下错误:ActiveRecord::SubclassNotFound (Invalid single-table inheritance type: HOME is not a subclass of Quotes)
我不明白为什么它认为它是继承的,因为它不应该继承。我的创建方法如下所示:
quote = Quotes.create(
agent_id: agent.id,
client_id: client.id,
type: 'HOME',
status: 0,
date_created: DateTime.now
)
如果我注释掉类型,一切正常。但是 Type it 错误。
最佳答案
我通过将模型继承列设置为 nil 解决了这个问题。 Active Record 模型可以通过属性 :type
从表中继承。 ,将inheritance_column 设置为nil 将删除该属性,允许您拥有一个名为type
的数据库列。
class Quote < ActiveRecord::Base
self.inheritance_column = nil
end
关于ruby-on-rails-4 - 导轨 : Invalid single-table inheritance type error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18243367/