Class table inheritance in Ruby on Rails
In my previous post I wrote about trying to get class table inheritance working in Rails. I passed by the hack and went with the plugin which ended up not really working right. I revisited the class table inheritance hack and actually got it working. I pretty much just dumped that code into a plugin so all you have to do is:
spaghetti.rb
noodle.rb
One thing that did trip me up at first was that the spaghettis table can’t have an ‘id’ column for a primary key or you end up with some strange stack overflow errors. The noodles table also needs a ‘type’ varchar column to store the class names of the rows its storing. Even pagination works when you explicitly state what tables you’re conditions are using as in:
Download the class_table_inheritance plugin

October 12th, 2007 at 11:19 pm
Hi, i have a problem with the plugin.
I have:
table publication:
id
title
author
type
table book:
publication_id
editor
publication.rb
class Publication
October 13th, 2007 at 7:06 am
class Publication
October 14th, 2007 at 12:41 pm
sory, the minor signus is not allowed…
i have this:
publication.rb
class Publication ‘inherits’ ActiveRecord::Base
end
book.rb
class Book ‘inherits’ Publication
class_table_inheritance
end
When i do, book/show or book/list only shows the attributes of Publication.
There is something that i’m doing wrong???
Thanks. Gonzalo
Sory if my english is a little poor…