Skip to content

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
@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