Fix BelongsToMorphed not clearing morph type on null relation#555
Merged
Fix BelongsToMorphed not clearing morph type on null relation#555
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #555 +/- ##
=========================================
Coverage 91.75% 91.75%
- Complexity 1962 1963 +1
=========================================
Files 131 131
Lines 5031 5034 +3
=========================================
+ Hits 4616 4619 +3
Misses 415 415 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 What was changed
Fix BelongsToMorphed not clearing morph type when relation is set to null
When setting a BelongsToMorphed relation to null, only the foreign key(parent_id) was being cleared while the morph discriminator (parent_type)retained its previous value. This left the database in an inconsistentstate with parent_type pointing to a role but parent_id being NULL.
The fix makes BelongsTo::setNullFromRelated() overridable (private → protected) and overrides it in BelongsToMorphed to also register the morphKey as null.
📝 Checklist