Rails - 使用没有 STI 的类型列? [英] Rails -- use type column without STI?

查看:28
本文介绍了Rails - 使用没有 STI 的类型列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不调用单表继承 (STI) 的情况下使用名为 type 的列 - 我只希望 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?

推荐答案

在 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 的类型列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆