tobyzerner / json-api-server

A JSON:API server implementation in PHP.
https://tobyzerner.github.io/json-api-server/
MIT License
63 stars 21 forks source link

fix: allow invalid nested includes for morph #99

Closed SychO9 closed 6 months ago

SychO9 commented 7 months ago

Hello 👋🏼,

This PR allows the scenario where you have a morph relationship (collection of resources on a relationship) and you include a nested relationship which only exists on one of the resources from the collection.

Prior to the changes here, that would not be possible and an exception would be thrown.

For example:

If you have a morph relation subject of types (users, posts) and only posts has the relation author. Including subjet.author would not be possible.

tobyzerner commented 6 months ago

@SychO9 I've just added a test for this issue, and fixed an issue with includes not working for polymorphic relationships that point to collections. I don't think the code you've proposed is necessary. Can you verify that this solves your issue, or if not, come up with a failing test?

SychO9 commented 6 months ago

@tobyzerner can confirm that has solved it 👍🏼