datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Concerns\NotificationContext;
|
|
use App\Models\Concerns\Reportable;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Change proposal
|
|
*
|
|
* @property Row[]|Collection $addedRows
|
|
* @property Row[]|Collection $removedRows
|
|
*/
|
|
class Proposal extends Model
|
|
{
|
|
use Reportable;
|
|
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 */
|
|
public function author()
|
|
{
|
|
return $this->belongsTo(User::class, 'author_id');
|
|
}
|
|
|
|
/** Target revision */
|
|
public function revision()
|
|
{
|
|
return $this->belongsTo(Revision::class);
|
|
}
|
|
|
|
/** Target table (that this was submitted to) */
|
|
public function table()
|
|
{
|
|
return $this->belongsTo(Table::class);
|
|
}
|
|
}
|
|
|