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

fix: detach should not destroy attachment #2034

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

Paul-Bob
Copy link
Contributor

Description

This change intended to make sure that validations / callbacks are called when detaching a record from a has_many associations. Unfortunately it introduced a bug where the record getting detached is actually deleted from DB.

destroy(*records)

...
This method will always remove record from the database ignoring the :dependent option.
...

Delete is what we want here but delete(*records) will not run associations callbacks...

Fixes https://discord.com/channels/740892036978442260/1157144752752427048

We should find a way to trigger associations callbacks using delete or another strategy.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

@Paul-Bob Paul-Bob added the Fix label Nov 16, 2023
@Paul-Bob Paul-Bob self-assigned this Nov 16, 2023
Copy link

codeclimate bot commented Nov 16, 2023

Code Climate has analyzed commit 0401834 and detected 0 issues on this pull request.

View more on Code Climate.

@Paul-Bob Paul-Bob merged commit 43aca11 into main Nov 20, 2023
12 of 14 checks passed
@Paul-Bob Paul-Bob deleted the fix/detach_should_not_destroy_attachment branch November 20, 2023 12:45
Copy link
Contributor

This PR has been merged into main. The functionality will be available in the next release.

Please check the release guide for more information.

@Paul-Bob
Copy link
Contributor Author

delete triggered before_remove and after_remove on my tests...

@yshmarov
Copy link
Contributor

yshmarov commented Dec 1, 2023

thanks!

@adrianthedev
Copy link
Collaborator

This should be out in nothe Avo 2 & 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants