Skip to content

Fix deleting courses and codes (coursecodes FK constraint) - #1238

Merged
fvacek merged 1 commit into
Quick-Box:mainfrom
VoiToi:fix/1237-delete-courses-codes
Oct 4, 2026
Merged

fvacek merged 1 commit into
Quick-Box:mainfrom
VoiToi:fix/1237-delete-courses-codes

Conversation

@VoiToi

@VoiToi VoiToi commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #1237

Deleting a course in Classes → Courses or a code in Classes → Codes failed on the coursecodes foreign key constraint (ON DELETE RESTRICT), because both dialogs used a plain SqlTableModel which only runs DELETE FROM courses/codes WHERE id=….

Changes

  • Courses (EditCoursesWidget): deleting a course deletes its coursecodes rows in the same transaction. A course still assigned to a class (classdefs.courseId) or a run (runs.courseId) is not deleted, the user gets a readable message (class names + stage, or run count) instead of an SQL error.
  • Codes (EditCodesWidget): a code used in a course is not deleted, the message lists the courses using it (first 10 + "and N more").
  • The checks run in dropRows() before beginRemoveRows(), so a refused delete does not leave the view showing the row as removed.
  • Confirmation: new TableView::setRemoveRowsQuestion() to replace the generic "Do you really want to remove row?" question. Courses ask "Do you really want to delete N course(s) including their codes? This cannot be undone.", codes ask a similar question. Default button stays No.
  • Czech translations for the new strings.

Testing

  • Built with Qt 6.11.2 / MinGW 13.1 (Release), no warnings in the changed files.
  • Root cause verified on a real relay event DB (PostgreSQL, 1077 courses / 124 codes / 21700 coursecodes): no other table references courses/codes except coursecodes, classdefs.courseId, runs.courseId.
  • The new delete paths have not been clicked through in the running app yet.

🤖 Generated with Claude Code

Deleting a course or a code in Classes -> Courses / Codes failed on
coursecodes foreign key constraint (ON DELETE RESTRICT).

- deleting a course deletes its coursecodes too, course assigned to
  a class or a run is not deleted and readable message is shown
- code used in a course is not deleted, message lists the courses
- checks are done before rows are removed from the model, so the view
  stays consistent when delete is refused
- TableView::setRemoveRowsQuestion() for custom delete confirmation,
  used for courses and codes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fvacek
fvacek merged commit bb1177a into Quick-Box:main Oct 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Courses and codes cannot be deleted: coursecodes foreign key constraint

2 participants