-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conditional Relationships in API Resource breaks relationship endpoints #130
Comments
Thanks for reporting. |
@helmroos any solution? |
There's probably no work around for this - it needs me to have time to implement a fix, or for someone else to submit a PR fixing it. |
@lindyhopchris so I noticed that within the relationship method in theJsonApiResource Class, conditional relationships are given as a ConditionalField object and not as Relation Object... Barely fiddling with the code because I don't understand sh*t of what is going on (pardon my french) I managed to pass all the test (relationship endpoints) by re-writing the relationship method to...
This works but I do not understand neither why, nor how... I would've thought that instead of calling ($relation)() I could've just called $relation->get() but this throws a serialization error... does this work around seem logical? |
I think it should actually be checking whether |
how would one "resolve it"? |
leaving a note that my solution of
only works with when and not mergeWhen, for ConditionalFields is not callable, as is ConditionalField... |
Will be in the |
Using Conditional Relationships in a API Resource class breaks the relationship self/related endpoints.
How to repro
/users/:id?include=team
/users/:id/team
/users/:id/relationships/team
/users/:id?include=team
=> ✅ 200 OK/users/:id/team
=> ☠️ 500 INTERNAL SERVER ERROR/users/:id/relationships/team
=> ☠️500 INTERNAL SERVER ERRORStacktrace
Response
Other details
I can repro both in PHPUnit and manually, using either a Web (Laravel Sanctum) or API (Laravel Passport) guard with the folllowing in composer.json:
php -v:
The text was updated successfully, but these errors were encountered: