I have a Post class, with TextPost, ImagePost, and LinkPost subclasses (using STI). These Post types are specified as strings in Post.type (as per STI convention).
I can call TextPost.all, ImagePost.all, and LinkPost.all just fine.
I thought I’d still be able to call Post.all, but I’m getting the following error:
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'text'. 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 Post.inheritance_column to use another column for that information.
For reference, here is the relevant part of my schema.rb:
create_table "posts", :force => true do |t|
t.string "title"
t.string "type"
t.integer "author_id"
t.datetime "publish_datetime"
...
end
And my subclasses (each in their own appropriately-named .rb file):
class TextPost < Post
...
end
class ImagePost < Post
...
end
class LinkPost < Post
...
end
Am I doing something wrong? Or is it just not possible to (simply & succinctly) call the parent class when using STI?
Sounds like you have a row in your database with the type column equal to “text”. Rails is trying to STI that to a
textclass. Looks like what you want isTextPostin the type column, nottext.