Skip to content

RuntimeException <Custom collection class> must implement Tobyz\\JsonApiServer\\Resource\\Findable #93

Closed
@bertramakers

Description

@bertramakers

Hi @tobyzerner .

I ran into an issue today that apparently this syntax doesn't work anymore for defining polymorphic relationships:

ToOne::make('example')
  ->type([
    Model1::class => 'model1',
    Model2::class => 'model2',
  ])

When I define it like that and create a new resource with this relationship, the related resource is always of the type model1 even though I explicitly put model2 in the request.

I read here that polymorphic relationships should now be defined using a custom CollectionInterface implementation: https://tobyzerner.github.io/json-api-server/relationships.html#polymorphic-relationships

However when I follow the documentation to define the collection and I send a request to create a new resource with the polymorphic relationship, I get the following error:

RuntimeException "<Custom collection class> must implement Tobyz\\JsonApiServer\\Resource\\Findable"

Note that I have registered the collection, and that I have defined it on the ToOne relationship using ->collection() instead of ->type().

This is quite an urgent issue for me because I had already updated and merged all the code that was broken with the recent updates, but I overlooked this one and now I can't seem to fix it because I'm not sure how to implement Findable on my collection. It just gets passed $id and $context, but no info on the type that is supposed to be loaded. And I cannot deduce that from the $id alone because our app uses incremental ids for every resource type, so they're not unique sadly.

Additionally, I'm not sure why the collection needs to implement Findable? All of the types I return in resources() on my collection also are registered resources, so their respective resource classes can be used to find the model?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions