Skip to content

Commit 28cd934

Browse files
authored
MSSQL removed cascade actions from DB level to model (#71)
1 parent 83057b1 commit 28cd934

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

migrations/2020_05_27_103953_create_custom_field_relations_table.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public function up()
1717
Schema::create('custom_field_relations', function (Blueprint $table) {
1818
if (config('asseco-custom-fields.migrations.uuid')) {
1919
$table->uuid('id')->primary();
20-
$table->foreignUuid('parent_id')->constrained('custom_fields')->cascadeOnDelete();
21-
$table->foreignUuid('child_id')->constrained('custom_fields')->cascadeOnDelete();
20+
$table->foreignUuid('parent_id')->constrained('custom_fields');
21+
$table->foreignUuid('child_id')->constrained('custom_fields');
2222
} else {
2323
$table->id();
24-
$table->foreignId('parent_id')->constrained('custom_fields')->cascadeOnDelete();
25-
$table->foreignId('child_id')->constrained('custom_fields')->cascadeOnDelete();
24+
$table->foreignId('parent_id')->constrained('custom_fields');
25+
$table->foreignId('child_id')->constrained('custom_fields');
2626
}
2727

2828
MigrationMethodPicker::pick($table, config('asseco-custom-fields.migrations.timestamps'));

src/App/Models/CustomField.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ protected static function booted()
6060
}
6161
}
6262
});
63+
64+
static::deleted(function (self $customField) {
65+
$customField->parent()->delete();
66+
$customField->children()->delete();
67+
});
6368
}
6469

6570
public function selectable(): MorphTo

0 commit comments

Comments
 (0)