Hi, I'm Benedikt Deicke, and I'm a freelance web and software developer. I'm mainly building user focused web applications using Ruby on Rails and JavaScript. Additionally I'm currently studying for my master's degree and enjoying photography in my spare time. Feel free to get in touch with me, I'm available for hire!

September 21st, 2007
ActiveRecord: Using the "type"-column

By default it’s not possible to use a database-column called “type” for anything else than single table inheritance. To change this, simply use set_inheritance_column() and read_attribute():

   1  class TypeTest < ActiveRecord::Base
   2    set_inheritance_column(:something_else)
   3  
   4    def type()
   5      read_attribute(:type)
   6    end
   7  
   8    def type=(value)
   9      write_attribute(:type, value)
  10    end
  11  end
Posted by benediktFiled in Articles, Ruby on Rails
Bookmark and Share

Leave a comment