From 93fc29f742e2179b24b5aa03987009ffc74a57ad Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Feb 2026 10:18:39 +0000 Subject: [PATCH 1/3] Initial plan From f19a39098a59bdf1c0b528d3eb3d8c99e950a31f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Feb 2026 10:28:07 +0000 Subject: [PATCH 2/3] Add deleting model event to ComponentGroup to detach components on deletion Co-authored-by: jbrooksuk <246103+jbrooksuk@users.noreply.github.com> --- src/Models/ComponentGroup.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Models/ComponentGroup.php b/src/Models/ComponentGroup.php index 3a72da1a..92ef0a06 100644 --- a/src/Models/ComponentGroup.php +++ b/src/Models/ComponentGroup.php @@ -47,6 +47,13 @@ class ComponentGroup extends Model 'visible', ]; + protected static function booted(): void + { + static::deleting(function (ComponentGroup $componentGroup): void { + $componentGroup->components()->update(['component_group_id' => null]); + }); + } + /** * Get the components in the group. * From c431a706e026e8a893af634f743c33ea1c053bd0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Feb 2026 11:49:56 +0000 Subject: [PATCH 3/3] Add model-level tests for component detachment on group deletion Co-authored-by: jbrooksuk <246103+jbrooksuk@users.noreply.github.com> --- tests/Unit/Models/ComponentGroupTest.php | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/Unit/Models/ComponentGroupTest.php b/tests/Unit/Models/ComponentGroupTest.php index df603bb4..5a34891b 100644 --- a/tests/Unit/Models/ComponentGroupTest.php +++ b/tests/Unit/Models/ComponentGroupTest.php @@ -157,3 +157,28 @@ // Should be expanded expect($group->fresh()->isExpanded())->toBeTrue(); }); + +it('resets component_group_id on components when the group is deleted', function () { + $group = ComponentGroup::factory()->hasComponents(2)->create(); + $componentIds = $group->components->pluck('id'); + + $group->delete(); + + foreach ($componentIds as $id) { + $this->assertDatabaseHas('components', [ + 'id' => $id, + 'component_group_id' => null, + ]); + } +}); + +it('does not delete components when the group is deleted', function () { + $group = ComponentGroup::factory()->hasComponents(2)->create(); + $componentIds = $group->components->pluck('id'); + + $group->delete(); + + foreach ($componentIds as $id) { + $this->assertDatabaseHas('components', ['id' => $id]); + } +});