From 027b2e13e99af15d99bbd848f3cde305f1a04665 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Thu, 15 Dec 2016 20:09:59 +0000 Subject: [PATCH] Delete related points when deleting metrics --- app/Models/Metric.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/Models/Metric.php b/app/Models/Metric.php index abafbd340..5ddeafc5a 100644 --- a/app/Models/Metric.php +++ b/app/Models/Metric.php @@ -141,6 +141,21 @@ class Metric extends Model implements HasPresenter 'visible', ]; + /** + * Overrides the models boot method. + * + * @return void + */ + public static function boot() + { + parent::boot(); + + // When deleting a metric, delete the points too. + self::deleting(function ($model) { + $model->points()->delete(); + }); + } + /** * Get the points relation. *