From: Lou Vanek Date: 2005-11-07T07:05:28+09:00 Subject: Re: Basic help with understanding RoR Inheritance You might try one 'Vehicle' table that holds all common fields, and a bunch of other tables (Cars, Trucks, Motorcycles, etc.) common to each vehicle that only holds fields specific to that type of vehicle. class Trucks < ActiveRecord::Base has_one :vehicle . . . end class Cars < ActiveRecord::Base has_one :vehicle . . . end class Motorcycles < ActiveRecord::Base has_one :vehicle . . . end class Vehicles < ActiveRecord::Base #belongs_to :truck # this probably wouldn't work. Not sure what to do here. #fields common to all: trucks, cars, motorcycles, etc. . . . end I haven't tried this type of schema but it seems like it might work. -lv TomRossi7 wrote: > I'm sorry for the newbie question, but I can't seem to find a basic > enough explanation for what I am looking for. Basically, I am trying > to understand Ruby on Rails Single Table Inheritance and the required > database structure for easy ActiveRecord integration. Here is a simple > example that I would be very grateful for assistance: > > Imagine you want to create an application built for tracking vehicle > information. You have a super-class Vehicle with attributes like VIN, > manufacturer, manufacturer date etc. -- all of the attributes that are > shared by all vehicles. Then you have sub-classes like car, truck, > motorcycle, etc. These sub-classes have unique attributes like maybe a > "towing capacity" for trucks [Granted, the attributes aren't that > dissimilar between a car and a truck, but this is just an example]. > > So, how would this best be modeled in the database and RoR? I am > thinking a model (class) for Vehicle, Car, Truck, Motorcyle. The > tables would be vehicles, cars, trucks, motorcylces. They each would > have id's and the vehicle table would track for each id the "type" of > vehicle. > > Am I on the right track? > > Thanks, > Tom > > >