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.
datatable.directory/app/Models/Revision.php

71 lines
1.8 KiB

6 years ago
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
6 years ago
use Riesjart\Relaquent\Model\Concerns\HasRelaquentRelationships;
/**
* Table revision (a set of rows)
*
* @property int $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property int $refs
* @property int $ancestor_id
* @property string $note
6 years ago
* @property object $columns
* @property Revision|null $parentRevision
* @property Row[]|Collection $rows
* @property Proposal|null $sourceProposal - proposal that was used to create this revision
* @property Proposal[]|Collection $dependentProposals
6 years ago
*/
class Revision extends Model
{
use HasRelaquentRelationships;
6 years ago
protected $guarded = [];
6 years ago
protected static function boot()
{
parent::boot();
static::deleting(function(Revision $self) {
// update refcounts
$self->rows()->decrement('refs');
$self->rows()->where('refs', '<=', 0)->delete();
});
}
6 years ago
/** Included rows */
public function rows()
{
return $this->belongsToMany(Row::class, 'revision_row_pivot');
}
/** Proposal that lead to this revision */
public function sourceProposal()
6 years ago
{
return $this->hasOneThrough(Proposal::class, 'revision_proposal_pivot');
}
/** Proposals that depend on this revision */
public function dependentProposals()
{
return $this->hasMany(Proposal::class);
}
/** Revision this orignates from */
public function parentRevision()
{
return $this->belongsTo(Revision::class, 'ancestor_id');
}
/** Tables referencing this revision */
public function tables()
{
return $this->belongsToMany(Table::class, 'table_revision_pivot');
}
}