In my Rails application, I have a multi-level hierarchy of the following form:
class Vehicle < ActiveRecord::Base end class RoadVehicle < Vehicle end class Car < RoadVehicle end class Buss < RoadVehicle end
Then I have a class that references the middle level as follows:
class Garage < ActiveRecord::Base has_many :road_vehicles end
In this simplified example, I gave the vehicle table a type column to enable unidirectional inheritance. In addition, it contains a garage_id column to include has_many relationships. When I create a new garage and add cars and buses, they will all be added to the database, as expected. However, when I later get the garage object and check the road_vehicles collection, it is empty. Can someone tell me what I am doing wrong?
ruby-on-rails associations single-table-inheritance
Pascal lindelauf
source share