got rid of proposal-column references

This commit is contained in:
2018-07-14 14:41:59 +02:00
parent 7493d3e176
commit 8efa08b1cc
5 changed files with 4 additions and 99 deletions
-23
View File
@@ -18,29 +18,6 @@ class Proposal extends Model
use Reportable; use Reportable;
use NotificationContext; use NotificationContext;
protected static function boot()
{
parent::boot();
static::deleting(function(Proposal $self) {
// update refcounts
$self->addedRows()->decrement('refs');
$self->removedRows()->decrement('refs');
});
}
/** Added rows */
public function addedRows()
{
return $this->belongsToMany(Row::class, 'proposal_add_row_pivot');
}
/** Removed rows */
public function removedRows()
{
return $this->belongsToMany(Row::class, 'proposal_remove_row_pivot');
}
/** Authoring user */ /** Authoring user */
public function author() public function author()
{ {
@@ -19,8 +19,8 @@ class CreateRevisionsTable extends Migration
$table->unsignedInteger('refs'); // used for reference counting $table->unsignedInteger('refs'); // used for reference counting
$table->unsignedInteger('ancestor_id')->index()->nullable(); // parent revision $table->unsignedInteger('ancestor_id')->index()->nullable(); // parent revision
// a column that can be used as the primary key for a table; possibly a composite column if using a comma // a column that can be used as the primary key for a table; possibly a composite column, if using a comma
$table->string('index_column')->nullable(); $table->string('index_column');
// author's note describing what has been changed // author's note describing what has been changed
$table->text('note'); $table->text('note');
@@ -25,6 +25,8 @@ class CreateProposalsTable extends Migration
$table->text('note'); $table->text('note');
$table->jsonb('changes'); // the actual meat of the changeset is stored here
// block the delete - we must first decrement Row refs and then the proposals manually // block the delete - we must first decrement Row refs and then the proposals manually
$table->foreign('revision_id')->references('id')->on('revisions') $table->foreign('revision_id')->references('id')->on('revisions')
->onDelete('restrict'); ->onDelete('restrict');
@@ -1,37 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProposalRemoveRowPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('proposal_remove_row_pivot', function (Blueprint $table) {
$table->unsignedInteger('proposal_id')->index();
$table->unsignedInteger('row_id')->index();
$table->foreign('proposal_id')->references('id')->on('proposals')
->onDelete('cascade');
$table->foreign('row_id')->references('id')->on('rows')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('proposal_remove_row_pivot');
}
}
@@ -1,37 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProposalAddRowPivotTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('proposal_add_row_pivot', function (Blueprint $table) {
$table->unsignedInteger('proposal_id')->index();
$table->unsignedInteger('row_id')->index();
$table->foreign('proposal_id')->references('id')->on('proposals')
->onDelete('cascade');
$table->foreign('row_id')->references('id')->on('rows')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('proposal_add_row_pivot');
}
}