Skip to content

Honor dependent associations during STI teardown - #65

Merged
nertzy merged 1 commit into
masterfrom
honor-sti-dependent-destruction
Aug 7, 2026
Merged

Honor dependent associations during STI teardown#65
nertzy merged 1 commit into
masterfrom
honor-sti-dependent-destruction

Conversation

@nertzy

@nertzy nertzy commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • destroy temporary table(false) STI rows through Active Record so callbacks and dependent associations run during teardown
  • preserve exact STI scoping, superclass default-scope bypass, and sibling/superclass rows
  • raise ActiveRecord::RecordNotDestroyed when a callback aborts cleanup rather than silently leaving an unloadable STI row
  • add regression coverage for foreign-key-protected dependent: :destroy records and aborted destruction

Closes #64

Test plan

  • Reproduced the foreign-key failure with the previous delete_all teardown
  • Verified the aborted-destruction spec fails under non-bang destroy_all
  • Ran mise x -- bin/rake (132 RSpec examples; 10 minitest runs; StandardRB)

@nertzy
nertzy force-pushed the honor-sti-dependent-destruction branch 7 times, most recently from 5eac8b4 to a155f6c Compare August 7, 2026 19:55
Destroy temporary STI rows through Active Record so callbacks and dependent associations run during teardown. Raise when destruction is aborted instead of silently leaving an unloadable row.

Fixes #64
@nertzy
nertzy force-pushed the honor-sti-dependent-destruction branch from a155f6c to 5dd59b9 Compare August 7, 2026 20:00
@nertzy
nertzy merged commit 5dd59b9 into master Aug 7, 2026
14 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.

STI teardown can violate foreign keys when the temporary model has dependent rows

1 participant