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
+16
View File
@@ -24,6 +24,22 @@ class Proposal extends Model
{
use Reportable;
protected static function boot()
{
parent::boot();
static::deleting(function(Proposal $self) {
$self->reportsOf()->delete();
// update refcounts
$rev = $self->revision;
$rev->decrement('refs');
// Delete the revision if it has no other refs (manually, to update row refs)
if ($rev->refs <= 0) $rev->delete();
});
}
/** Authoring user */
public function author()
{