Determine type in polymorphic relation

I think that you should create some kind of an interface, for example Vehicle, like this:

class Vehicle < ActiveRecord::Base   belongs_to :person, :polymorphic => true end

After that you should make the inherited models Car and Truck:

class Car < Vehicle end

class Truck < Vehicle end

and finally define the person model:

class Person < ActiveRecord::Base   has_many :vehicles end

Keep in mind that the Vehicle table should have a string column :type, where the class of the record is stored.

With this models you can do this:

p = Person.create(:name => "John") p.vehicles << Car.create(:model => "Fiat") p.vehicles << Truck.create(:model => "Mercedes")

For more information:

Does that help answer your question?

--Valentin