Thursday, July 1, 2010

The single-table inheritance mechanism failed to locate the subclass: 'regular'

If you get the following when trying to use ActiveRecord to view legacy tables in a database:
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1667:in `instantiate': The single-table inheritance mechanism failed to locate the subclass: 'regular'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite NameOfYourModel.inheritance_column to use another column for that information. (ActiveRecord::SubclassNotFound)
Add this before your model definitions:
ActiveRecord::Base.inheritance_column = "activerecordtype"

No comments: