Detach components from group on deletion via model event#330
Merged
Conversation
…letion Co-authored-by: jbrooksuk <246103+jbrooksuk@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix deletion of components from component group
Detach components from group on deletion via model event
Feb 24, 2026
Member
|
@copilot add tests to verify this behavior. |
Co-authored-by: jbrooksuk <246103+jbrooksuk@users.noreply.github.com>
Contributor
Author
Added two tests to
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Deleting a component group via the Filament admin (single or bulk) left orphaned components with a dangling
component_group_id, making them invisible on the status page and rendering only the raw ID in the admin UI.The
DeleteComponentGroupaction already nullifiedcomponent_group_idcorrectly, but Filament's built-inDeleteAction/DeleteBulkActioncall$model->delete()directly, bypassing that action entirely.Changes
ComponentGroupmodel — add adeletingEloquent event inbooted()that nullifiescomponent_group_idon all related components before the group is removed. This makes the detachment unconditional regardless of the deletion path (API action, Filament single/bulk delete, or direct model call).The explicit
updatecall inDeleteComponentGroupbecomes redundant but harmless — it now runs twice in the API path, which is a no-op on the second pass.tests/Unit/Models/ComponentGroupTest.php— added two tests that directly exercise the model event (bypassing the action class, matching the Filament delete path):resets component_group_id on components when the group is deleted— asserts all related components havecomponent_group_id = nullafter$group->delete().does not delete components when the group is deleted— asserts the components themselves still exist in the database after the group is deleted.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.