Rename component.component to component_id with relationship name change

This commit is contained in:
James Brooks
2014-12-01 12:21:44 +00:00
parent 0ae06acac2
commit e0dd2ef909
2 changed files with 41 additions and 7 deletions

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterTableIncidentsRenameComponentColumn extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('incidents', function(Blueprint $table)
{
DB::statement("ALTER TABLE `incidents` CHANGE `component` `component_id` TINYINT(4) NOT NULL DEFAULT '1'");
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('incidents', function(Blueprint $table)
{
DB::statement("ALTER TABLE `incidents` CHANGE `component_id` `component` TINYINT(4) NOT NULL DEFAULT '1'");
});
}
}

View File

@@ -8,11 +8,11 @@ class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableI
use Illuminate\Database\Eloquent\SoftDeletingTrait;
protected $rules = [
'user_id' => 'required|integer',
'component' => 'required|integer',
'name' => 'required',
'status' => 'required|integer',
'message' => 'required',
'user_id' => 'required|integer',
'component_id' => 'required|integer',
'name' => 'required',
'status' => 'required|integer',
'message' => 'required',
];
protected $fillable = ['component', 'name', 'status', 'message'];
@@ -23,8 +23,8 @@ class Incident extends Eloquent implements \Dingo\Api\Transformer\TransformableI
* An incident belongs to a component.
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent() {
return $this->belongsTo('Component', 'component', 'id');
public function component() {
return $this->belongsTo('Component', 'component_id', 'id');
}
/**