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

feat: MorphTo serialization #97

Closed SychO9 closed 6 months ago

SychO9 commented 7 months ago

Hello 👋🏼,

When using a MorphTo relation, the $relation->getRelated() returns an instance of the parent model instead of the expected related model. So the serialization ends up using the wrong model class to find the appropriate resource class.

tobyzerner commented 6 months ago

Could we use MorphTo::createModelByType() here?

SychO9 commented 6 months ago

done 👍🏼

tobyzerner commented 6 months ago

Thanks! I just removed a line I don't think is necessary, because createModelByType already calls Model::getActualClassNameForMorph() (the equivalent of MorphTo::getMorphedModel($morphType) ?? $morphType) - but let me know if this doesn't work.