I am using single table inheritance in my rails application, and want to explicitly set the type of an instance.
I have
class Event < ActiveRecord::Base
class SpecialEvent < Event
Implemented through single table inheritance.
SpecialEvent.new
works as expected,
but I want to be able to do things like
Event.new(:type => 'SpecialEvent')
So I can create different sub_types easily in the application.
However this doesn't work and seems to set :type
to nil
, not the value I set it to;
I suspect this is because by calling Event.new
it is overwriting the :type
argument.
Has anyone got a good way of doing this?