-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider foreign key constraints with isRelationNullable (#1231)
* Consider foreign key constraints with isRelationNullable * test: add belongsTo Variation * command: composer test-regenerate
- Loading branch information
1 parent
b268871
commit 52a4b64
Showing
4 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
31 changes: 31 additions & 0 deletions
31
tests/Console/ModelsCommand/Relations/Models/BelongsToVariation.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class BelongsToVariation extends Model | ||
{ | ||
public function notNullColumnWithForeignKeyConstraint(): BelongsTo | ||
{ | ||
return $this->belongsTo(self::class, 'not_null_column_with_foreign_key_constraint'); | ||
} | ||
|
||
public function notNullColumnWithNoForeignKeyConstraint(): BelongsTo | ||
{ | ||
return $this->belongsTo(self::class, 'not_null_column_with_no_foreign_key_constraint'); | ||
} | ||
|
||
public function nullableColumnWithForeignKeyConstraint(): BelongsTo | ||
{ | ||
return $this->belongsTo(self::class, 'nullable_column_with_foreign_key_constraint'); | ||
} | ||
|
||
public function nullableColumnWithNoForeignKeyConstraint(): BelongsTo | ||
{ | ||
return $this->belongsTo(self::class, 'nullable_column_with_no_foreign_key_constraint'); | ||
} | ||
} |
This file contains 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
23 changes: 23 additions & 0 deletions
23
tests/Console/ModelsCommand/migrations/____belongs_to_variation_table.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class BelongsToVariationTable extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::create('belongs_to_variations', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->integer('not_null_column_with_foreign_key_constraint'); | ||
$table->integer('not_null_column_with_no_foreign_key_constraint'); | ||
$table->integer('nullable_column_with_foreign_key_constraint')->nullable(); | ||
$table->integer('nullable_column_with_no_foreign_key_constraint')->nullable(); | ||
$table->foreign('not_null_column_with_foreign_key_constraint')->references('id')->on('belongs_to_variations'); | ||
$table->foreign('nullable_column_with_foreign_key_constraint')->references('id')->on('belongs_to_variations'); | ||
}); | ||
} | ||
} |