Links
Inherits From
Categories
Inherits From
Implements class table inheritance in ActiveRecord. A quick example:
create_table "books", :force => true do |t|
t.column "product_id", :integer
t.column "pages", :integer
t.column "author", :string
end
create_table "products", :force => true do |t|
t.column "name", :string
t.column "price", :integer
t.column "type", :string
end
create_table "videos", :force => true do |t|
t.column "product_id", :integer
t.column "minutes", :integer
t.column "starring", :string
end
class Product < ActiveRecord::Base
end
class Book < ActiveRecord::Base
inherits_from :product
end
class Video < ActiveRecord::Base
inherits_from :product
end
Book.create(:name => "Agile Development with Rails", :pages => 350)
Video.create(:name => "Twilight Zone Season 1", :minutes => 490)
Book.find(1).name => "Agile Development with Rails"
Vitals
| Home | http://www.raylucke.com/simple-class-table-inheritance-in-activerecord/ |
|---|---|
| Repository | http://github.com/rwl4/inherits_from/tree/master |
| License | Rails' (MIT) |
| Rating | (12 votes) |
| Owner | Ray Lucke |
| Created | 19 July 2006 |
