Today I Learned

hashrocket A Hashrocket project

Disable single table inheritance column in Rails

Due to ActiveRecord single table inheritance in Rails, the the attribute type is a reserved word by default. However, I like to use type when STI is not in the picture. We can do this per model by setting inheritance_column. Much like most things in Rails there is a sane default for convention but can be overrdiden. In this case we will be 'disabling' is by setting to nil

class Foo < ApplicationRecord
  self.inheritance_column = nil
end

Now you're free to use the type column as wish.

See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.