Feature: Add Config Option to Enforce Nullable Relationships (#1580)

* feat: add config option for nullable relationships

Introduce enforce_nullable_relationships configuration to control nullable Eloquent relationships.

* refactor: update logic for nullable relationships

Update isRelationNullable method to respect new config option.

* test: add tests for nullable relationship config

- Verify behavior of enforce_nullable_relationships configuration option.
- Create snapshot to reflect enforce_nullable_relationships set to false.

* docs: improve documented context and usage

* docs: update CHANGELOG with enforce_nullable_relationships option
This commit is contained in:
Jeramy Hing
2024-10-30 22:35:58 +01:00
committed by GitHub
parent 90e7c5ac47
commit 472c1bad5d
5 changed files with 312 additions and 1 deletions
+3 -1
View File
@@ -836,13 +836,15 @@ class ModelsCommand extends Command
$fkProp = $reflectionObj->getProperty('foreignKey');
$fkProp->setAccessible(true);
$enforceNullableRelation = $this->laravel['config']->get('ide-helper.enforce_nullable_relationships', true);
foreach (Arr::wrap($fkProp->getValue($relationObj)) as $foreignKey) {
if (isset($this->nullableColumns[$foreignKey])) {
return true;
}
if (!in_array($foreignKey, $this->foreignKeyConstraintsColumns, true)) {
return true;
return $enforceNullableRelation;
}
}