在Rails应用程序中更改ActiveRecord :: Base.inheritance_column [英] Change ActiveRecord::Base.inheritance_column in a rails app

查看:102
本文介绍了在Rails应用程序中更改ActiveRecord :: Base.inheritance_column的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用type以外的列使用单表继承".根据Rails文档- http://api.rubyonrails.org/classes/ActiveRecord/Base.html ,我可以通过修改ActiveRecord::Base.inheritance_column来实现.我该怎么办?

I want to use Single Table Inheritance using a column other than type. According to the Rails documentation - http://api.rubyonrails.org/classes/ActiveRecord/Base.html, I can do this by modifying ActiveRecord::Base.inheritance_column. How can I do this?

推荐答案

尝试以下操作:

class MyModel < ActiveRecord::Base
    self.inheritance_column = 'column_that_is_not_type'
end

您的迁移应该随处可见.

Your migrations should work everywhere.

这篇关于在Rails应用程序中更改ActiveRecord :: Base.inheritance_column的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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