Skip to content

fix: Make relation-generated FK nullable when any relation sharing it asks for nullable - #86

Merged
roxblnfk merged 1 commit into
2.xfrom
fix/migrations-17-nullable-fk
Oct 5, 2026
Merged

roxblnfk merged 1 commit into
2.xfrom
fix/migrations-17-nullable-fk

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Oct 5, 2026

Copy link
Copy Markdown
Member

🔍 What was changed

  • When several relations generate the same foreign key field (a HasMany and its BelongsTo(nullable: true) on comments.user_id), the column is nullable if any of them asks for nullable — no matter which entity comes first in the registry.
  • Fields declared by the user (#[Column], Field in the schema) are not changed by relations, as before.
  • Field gets an @internal marker setRelationGenerated() / isRelationGenerated() to tell the two kinds apart.

Review notes

  • Only nullability is merged. Other properties of a shared relation-generated field (type, typecast, attributes) are still taken from the first relation, and the morph type column (MorphTrait::ensureMorphField, nullable and length) still works first-come — the same order dependency, left out of scope here.

Checklist

… 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

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.29%. Comparing base (3a53db9) to head (940d327).
⚠️ Report is 1 commits behind head on 2.x.

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.
📢 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 e97646f into 2.x Oct 5, 2026
28 of 30 checks passed
@roxblnfk
roxblnfk deleted the fix/migrations-17-nullable-fk branch October 5, 2026 08:35
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.

Generates nullable columns incorrectly for HasMany relation

1 participant