Skip to content

Fix BelongsToMorphed not clearing morph type on null relation#555

Merged
roxblnfk merged 1 commit into2.xfrom
fix-btm-cleanup
Mar 3, 2026
Merged

Fix BelongsToMorphed not clearing morph type on null relation#555
roxblnfk merged 1 commit into2.xfrom
fix-btm-cleanup

Conversation

@roxblnfk
Copy link
Member

@roxblnfk roxblnfk commented Mar 2, 2026

🔍 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

  • How was this tested:
    • Unit tests added

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.75%. Comparing base (ea1fbb5) to head (7391f8b).
⚠️ Report is 1 commits behind head on 2.x.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roxblnfk roxblnfk merged commit ddded1e into 2.x Mar 3, 2026
28 of 30 checks passed
@roxblnfk roxblnfk deleted the fix-btm-cleanup branch March 3, 2026 05:50
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.

1 participant