I have a class, say, Car from which I have inherited classes Black and Red as follows:
class Car::Black < Car
end
class Car::Red < Car
end
Now, there is another class, say, CarPurchase which has many Cars of both varieties. The associations are as follows:
# In Black and Red models:
has_many :car_purchases, as: :purchasable, dependent:destroy
# In CarPurchase model:
belongs_to :purchasable, polymorphic: true
Now I'm trying to save the CarPurchases like this:
black_car.car_purchases.new() # black_car is an object of class Car::Black
My database has a column called purchasable_type. The problem is that records are saved with purchasable_type 'Car' and not 'Car::Black'. I tried saving the purchasable_type explicitly also while creating record. No luck. Help please.