I have an STI setup I'm using where all sti base classes get their core behavior from a module
module SingleTableInheritable
extend ActiveSupport::Concern
included do
def self.inherited(subclass)
subclass.class_eval do
def method_missing(method_name, *args, &block)
... some stuff
super
end
end
super
end
end
end
I then have many classes inheriting from this module. The method missing mysteriously work on all but one
An example of a class where undefined methods get picked up by method_missing in the module
class DataModule < ApplicationRecord
include SingleTableInheritable
has_and_belongs_to_many :action_coordinates, class_name: "ActionCoordinates"
has_and_belongs_to_many :datasets
has_many :data_sub_modules
belongs_to :interval, optional: true
belongs_to :hardware_device, optional: true
end
And the class which never trigger the method missing on undefined_methods
class DataSubModule < ApplicationRecord
include SingleTableInheritable
belongs_to :data_module
end
The only thing I noticed as a possible explanation is that DataSubModule
(the class that doesn't work) is the only table with a belongs_to
connection to another STI table. All other connections are many to many
and they all seem to get the correct behavior. But if I call the the relationships on the base classes it all works ie:
DataSubModule::Instance.first.data_module #this relationship works as normal
DataSubModule::Instance.first.some_undefined_method #this does not get picked up by the method missing
DataModule::Instance.first.some_undefined_method #this gets picked up by the method missing