Skip to content
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

feat: MorphTo serialization #97

Merged
merged 4 commits into from
Mar 31, 2024

Conversation

SychO9
Copy link
Contributor

@SychO9 SychO9 commented Feb 10, 2024

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
Copy link
Owner

Could we use MorphTo::createModelByType() here?

@SychO9
Copy link
Contributor Author

SychO9 commented Mar 30, 2024

done 👍🏼

@tobyzerner tobyzerner merged commit 4c3b44f into tobyzerner:main Mar 31, 2024
2 of 3 checks passed
@tobyzerner
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants