Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend before_destroy(s) in models with destroy dependents #4191

Merged
merged 1 commit into from
Oct 2, 2019
Merged

Prepend before_destroy(s) in models with destroy dependents #4191

merged 1 commit into from
Oct 2, 2019

Conversation

rhymes
Copy link
Contributor

@rhymes rhymes commented Oct 2, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

Description

While reviewing other PRs I noticed something and went confirming it with the Rails docs:

before_destroy callbacks should be placed before dependent: :destroy associations (or use the prepend: true option), to ensure they execute before the records are deleted by dependent: :destroy.

So if an object has objects that will be destroyed by association, its before_destroy callbacks should run before those objects are in turn destroyed.

I added prepend: true to the three models that match the scenario.

Related Tickets & Documents

See https://guides.rubyonrails.org/active_record_callbacks.html#destroying-an-object

@rhymes rhymes changed the title [WIP] Prepend before_destroy(s) in models with destroy dependents Prepend before_destroy(s) in models with destroy dependents Oct 2, 2019
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 2, 2019
@rhymes rhymes requested a review from lightalloy October 2, 2019 13:14
@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 2, 2019
@benhalpern benhalpern merged commit 757b1a8 into forem:master Oct 2, 2019
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Oct 2, 2019
@rhymes rhymes deleted the rhymes/before_destroy-prepend branch October 2, 2019 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants