|
|
@ -38,8 +38,15 @@ class Table extends Model |
|
|
|
parent::boot(); |
|
|
|
parent::boot(); |
|
|
|
|
|
|
|
|
|
|
|
static::deleting(function(Table $self) { |
|
|
|
static::deleting(function(Table $self) { |
|
|
|
// update refcounts |
|
|
|
// update revision refcounts |
|
|
|
$self->revisions()->decrement('refs'); |
|
|
|
$self->revisions()->decrement('refs'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$self->reportsOf()->delete(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// delete revisions with zero refs (manually, to properly cascade to rows) |
|
|
|
|
|
|
|
foreach ($self->revisions()->where('refs', '<=', 0)->get() as $rev) { |
|
|
|
|
|
|
|
$rev->delete(); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|