T
TomRossi7
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
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