This is admittedly a bit of an unusual situation, and (for reasons I don't yet understand) appears to still work as intended, so I'm mostly just documenting it here to provide a public reference point.
Consider the following models and resources:
class Machine < ActiveRecord::Base
has_many :parts
end
class Part < ActiveRecord::Base
belongs_to :machine
end
class Gadget < Part
# ...
end
class PartResource < JSONAPI::Resource
has_one :machine
end
class WidgetResource < PartResource
model_name 'Gadget'
end
On definition of the WidgetResource class, JR issues the following warning:
[MODEL NOT FOUND] Model could not be found for WidgetResource. If this a base Resource declare it as abstract.
This is caused by the inherited hook in JSONAPI::Resource, which ends up calling _model_class, and since this happens before model_name is called, the model class cannot be found. Since the call is related to associations, a workaround is to define the has_one :machine on each subclass instead of the superclass. Although, as I mentioned, even with the warning the association still seems to work.
This is admittedly a bit of an unusual situation, and (for reasons I don't yet understand) appears to still work as intended, so I'm mostly just documenting it here to provide a public reference point.
Consider the following models and resources:
On definition of the
WidgetResourceclass, JR issues the following warning:This is caused by the
inheritedhook inJSONAPI::Resource, which ends up calling_model_class, and since this happens beforemodel_nameis called, the model class cannot be found. Since the call is related to associations, a workaround is to define thehas_one :machineon each subclass instead of the superclass. Although, as I mentioned, even with the warning the association still seems to work.