I was wondering, how an association like the following might be done in Rails:
class Car < ActiveRecord::Base
belongs_to :person
end
class Truck < ActiveRecord::Base
belongs_to :person
end
class Person < ActiveRecord::Base
#How to do the association as below?
has_one :car or :truck
end
Essentially, I am trying to enforce that a Person
can have one Car
or one Truck
but cannot have both.
As a secondary, is there a solution where a Person
can have many Car
or many Truck
, but not a mix of both?
Any ideas on what's the way to do this?