From: James Edward Gray II Date: 2005-11-07T06:33:24+09:00 Subject: Re: Basic help with understanding RoR Inheritance On Nov 6, 2005, at 2:42 PM, 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? Close. Remember it's called "Single Table" Inheritance. That means you only make a "vehicles" table, and add a "type" field. ActiveRecord pretty much handles the rest. There's information on this in the Rails book, in case you want to know more. James Edward Gray II