mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 02:01:33 +00:00
Update migrations and add foreign key, update related models
This commit is contained in:
@@ -264,7 +264,7 @@ class Category extends Model
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(static::class, 'parentid');
|
||||
return $this->belongsTo(RootCategory::class, 'root_categories_id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,5 +6,11 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RootCategory extends Model
|
||||
{
|
||||
//
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function categories()
|
||||
{
|
||||
return $this->hasMany(Category::class, 'root_categories_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ChangeCategoriesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
$table->renameColumn('parentid', 'root_categories_id');
|
||||
$table->foreign(['root_categories_id'], 'fk_root_categories_id')->references('id')->on('root_categories')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('categories', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user