fix: Make relation-generated FK nullable when any relation sharing it asks for nullable - #86
Merged
Merged
Conversation
… asks for nullable A HasMany and its BelongsTo(nullable: true) generate the same foreign key column; the field was defined by whichever relation ran first, so the column nullability depended on the entity order in the registry. Fields created by a relation are now marked, and a later relation requesting nullable makes such a field nullable. Fields declared by the user are left untouched. Fixes cycle/migrations#17 Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #86 +/- ##
============================================
+ Coverage 95.27% 95.29% +0.02%
- Complexity 602 606 +4
============================================
Files 46 46
Lines 1734 1743 +9
============================================
+ Hits 1652 1661 +9
Misses 82 82 ☔ View full report in Codecov by Harness. 🚀 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
HasManyand itsBelongsTo(nullable: true)oncomments.user_id), the column is nullable if any of them asks for nullable — no matter which entity comes first in the registry.#[Column],Fieldin the schema) are not changed by relations, as before.Fieldgets an@internalmarkersetRelationGenerated()/isRelationGenerated()to tell the two kinds apart.Review notes
MorphTrait::ensureMorphField, nullable and length) still works first-come — the same order dependency, left out of scope here.Checklist
nullable => truein both orders