Rails 3 - Single-Table Inheritance (STI) issues with the "type" column

337 views
Skip to first unread message

Brooke Kuhlmann

unread,
Oct 4, 2010, 2:45:14 PM10/4/10
to Not Just Ruby
Anyone hitting issues with sub-classed models in Rails 3? For example:

"The single-table inheritance mechanism failed to locate the subclass:
'Employee'. 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 User.inheritance_column to use another column for
that information.

I have several models that use subclasses where the type is what
distinguishes them. Worked fine in Rails 2 but with Rails 3 I seem to
be hitting issues like this. I've run through the obvious issues of
making sure the class name is spelled correctly in the type column,
etc. It could also be an issue with a dependent gem too. Not sure yet.
Definitely annoying and haven't come across much literature on
resolving this yet.

Brooke Kuhlmann

unread,
Oct 13, 2010, 12:42:09 PM10/13/10
to Not Just Ruby
FYI:

I found the solution to this problem. It was a total PITA and I'm
still trying to track down the exact details as to why types are so
funky in Rails 3. The solution is to add the following to your models:

ActiveRecord::Base.inheritance_column = "activerecordtype"

In my case, I simply added this to my active_record.rb initializer
file which then prevented these annoying messages from popping up and
rendering my Rails 3 app useless.

"The single-table inheritance mechanism failed to locate the subclass"

Now that I'm finally on Rails 3 and have converted from Rails 2, I
have to say this was the hardest and obscure problem that I've come
across so far. Otherwise, things are much nicer in Rails 3 (well, once
you get pass all the deprecation warnings).
Reply all
Reply to author
Forward
0 new messages