graphiti
graphiti copied to clipboard
Inherited resources not rendering parent's attributes (w/ Null Adapter and polymorphism)
I have the following Resource:
module Api::V2
class RecognitionResource < BaseResource
self.adapter = Graphiti::Adapters::Null
self.polymorphic = [BarcodeResource, TokenResource]
belongs_to :page, foreign_key: :page_id, except: [:writable], resource: PageResource
attribute(:confidence, :float)
attribute(:coordinates, :hash)
attribute(:kind, :string)
attribute(:value, :string)
attribute(:id, :string)
attribute(:page_id, :string)
end
end
From which this resource inherits:
module Api::V2
class TokenResource < RecognitionResource
self.model = Recognitions::Token
self.type = "text"
end
I should add they don't use ActiveRecord models but instead plain ruby objects (with attr_accessors
in place for every attribute).
Now, if I move the attributes and association to the child resource this works fine. But if I leave them in the parent resource it renders no attributes and the association is not loaded.
Is there some library I should import? Thanks