Skip to content

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…#1261
jlugner wants to merge 1 commit intoJSONAPI-Resources:release-0-9from
Mevia:release-0-9

Conversation

@jlugner
Copy link
Copy Markdown

@jlugner jlugner commented Jun 18, 2019

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:

  • I've checked to ensure there aren't other open Pull Requests for the same update/change.
  • I've submitted a ticket for my issue if one did not already exist.
  • My submission passes all tests. (Please run the full test suite locally to cut down on noise from travis failures.)
  • I've used Github auto-closing keywords in the commit message or the description.
  • I've added/updated tests for this change.

Bug fixes and Changes to Core Features:

  • I've included an explanation of what the changes do and why I'd like you to include them.
  • I've provided test(s) that fails without the change.

Test Plan:

Reviewer Checklist:

  • Maintains compliance with JSON:API
  • Adequate test coverage exists to prevent regressions

Copy link
Copy Markdown
Contributor

@lgebhardt lgebhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
@lgebhardt
Copy link
Copy Markdown
Contributor

@Pungsnigel Thanks again! I added a test to the original commit.

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.

2 participants