Rails — use type column without STI?

前端 未结 5 1443
闹比i
闹比i 2020-11-27 15:36

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 Stri

5条回答
  •  时光说笑
    2020-11-27 16:12

    Rails 4.x

    I encountered the problem in a Rails 4 app, but in Rails 4 the set_inheritance_column method does not exist at all so you can't use it.

    The solution that worked for me was to disable the single table inheritance by overriding ActiveRecord’s inheritance_column method, like this:

    class MyModel < ActiveRecord::Base
    
      private
    
      def self.inheritance_column
        nil
      end
    
    end
    

    Hope it helps!

提交回复
热议问题