-
-
Notifications
You must be signed in to change notification settings - Fork 21
RuntimeException <Custom collection class> must implement Tobyz\\JsonApiServer\\Resource\\Findable
#93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
<Custom collection class> must implement Tobyz\\JsonApiServer\\Resource\\Findable
Also a small error in the documentation, the code example uses |
Hi @bertramakers, will look into this very soon! |
Thanks @tobyzerner! 🙏 |
Hi @tobyzerner , I was able to work around the issue for now by defining the polymorphic relationship like this:
And then following your advice from solution 2 in this comment: #72 (comment), to override the I suspect that is why my original relationship wasn't working anymore. I thought it actually saved the wrong resource type to the DB, but it was actually broken when returning the data from the DB because the new code doesn't look at the array keys anymore and requested a type from the first resource type it encountered in the list, and the base Resource::resource() implementation always returns its type. So this is now not urgent anymore for me, but I'll leave this open since the "official" approach to polymorphic relationships seems to be broken or not documented completely. |
Thanks for all the information @bertramakers, and sorry for the trouble. This should be fixed now - the resource specified in the linkage data will be used to find the model, rather than the relationship's collection. Let me know how you go - and if you have any ideas about how to document this better. I've just released 1.0.0-beta.3 which includes the fix, as well as dropping the |
Thanks for the update @tobyzerner ! Just updated to beta 3, and the docs with breaking changes were super clear. 👍 |
Hi @tobyzerner .
I ran into an issue today that apparently this syntax doesn't work anymore for defining polymorphic relationships:
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 putmodel2
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-relationshipsHowever 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:
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?The text was updated successfully, but these errors were encountered: