Revert "Use destroy instead of delete to ensure callbacks are cal…#1261
Closed
jlugner wants to merge 1 commit intoJSONAPI-Resources:release-0-9from
Mevia:release-0-9
Closed
Revert "Use destroy instead of delete to ensure callbacks are cal…#1261jlugner wants to merge 1 commit intoJSONAPI-Resources:release-0-9from Mevia:release-0-9
destroy instead of delete to ensure callbacks are cal…#1261jlugner wants to merge 1 commit intoJSONAPI-Resources:release-0-9from
Mevia:release-0-9
Conversation
…led" This reverts commit 5f8705a.
lgebhardt
approved these changes
Jul 9, 2019
Contributor
There was a problem hiding this comment.
@Pungsnigel Thanks for pointing this out. The commit was made in response to #1172, and your assessment of the desired behavior is correct. I'm guessing I made an erroneous assumption on how the methods worked on the CollectionProxy.
lgebhardt
added a commit
that referenced
this pull request
Jul 9, 2019
Contributor
|
@Pungsnigel Thanks again! I added a test to the original commit. |
12 tasks
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.
This reverts commit 5f8705a.
Solves #1260
I think the reverted commit was based on a misunderstanding of how delete vs destroy works for relationships. Calling destroy on an instance of ActiveRecord::Associations::CollectionProxy will actually not only remove the intended resource from the relationship, it will remove it from the database, no matter what dependency is set on the base model. Delete will remove the resource from the relationship, but will only destroy the resource if the base model has specified dependency: :destroy.
Destroying resources that should have been nullified feels quite dangerous? The JSONAPI specification doesn't mention what behaviour is expected apart from removing the relation, so I doubt needlessly destroying the underlying resource is what is expected.
Relevant docs:
ActiveRecord::Associations::CollectionProxy#delete
ActiveRecord::Associations::CollectionProxy#destroy
All Submissions:
Bug fixes and Changes to Core Features:
Test Plan:
Reviewer Checklist: