I was using single table inheritance lately and experienced the problem that a parent class did not know about its subclasses in development mode. The inheritance structure was like follows:
class Event < ActiveRecord::Base
end
class GlobalEvent < Event
end
class NewRegistrationEvent < GlobalEvent
end
class ConsultingRequestEvent < GlobalEvent
end
When I tried to load all global events in a controller, all I recieved by GlobalEvent.all
was an empty set even though there were some new registration events and consulting requests there. To make your parent class aware of its subclasses, you can force your parent class to load the subclass simply by calling require_dependency 'subclass.rb'
in your parent class. Now calling GlobalEvent.all
will return all events as expected.
Also check out the link below. That guy experienced the same problem within a controller:
when single table inheritance attacks
Show archive.org snapshot