add some missing auto-deletes if refcount reaches zero

This commit is contained in:
2018-07-21 19:47:44 +02:00
parent a9ffd378a0
commit dc9acbf9d7
5 changed files with 43 additions and 1 deletions
+8 -1
View File
@@ -38,8 +38,15 @@ class Table extends Model
parent::boot();
static::deleting(function(Table $self) {
// update refcounts
// update revision refcounts
$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();
}
});
}