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

[10.x] Set morph type for MorphToMany pivot model #48432

Merged
merged 4 commits into from
Sep 25, 2023

Conversation

gazben
Copy link
Contributor

@gazben gazben commented Sep 17, 2023

Discussion: #43760

If you have a MorphPivot entity with a custom class, when attaching a record, you get the pivot with all the fields loaded on the model, but if you detach it, you only get the IDs of both sides, so in case of morphPivots, you do not get the type/class of the entity so there's information missing and you cannot obtain the morph relation from the pivot because it throws an error.

With this change the morph type will be automatically added to the pivot attributes, so you can query the relation model from a listener for example.

@gazben gazben changed the title Set morph type for MorphToMany pivot model [10.x] Set morph type for MorphToMany pivot model Sep 17, 2023
@taylorotwell
Copy link
Member

Hey there - I think we would need tests for this.

@taylorotwell taylorotwell marked this pull request as draft September 18, 2023 14:54
@gazben
Copy link
Contributor Author

gazben commented Sep 24, 2023

@taylorotwell I've added the missing test to check for this use-case. If the newly added array_merge is commented out, the test fails because only the equipmentable_id attribute is present in the deleted() callback.

With the now modified attributes, the query will run.

@gazben gazben marked this pull request as ready for review September 24, 2023 16:21
@taylorotwell taylorotwell merged commit 124eeae into laravel:10.x Sep 25, 2023
20 checks passed
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