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 really_destroy used against a has_one relationship that is soft deleted #574

Open
wants to merge 1 commit into
base: core
Choose a base branch
from

Conversation

reedstonefood
Copy link

I found a bug. The test explains the scenario but I'll explain it here as well.

Given:

class MyModel < ActiveRecord::Base
  acts_as_paranoid
  has_one: linked_model, dependant: destroy
end

class LinkedModel < ActiveRecord::Base
  acts_as_paranoid
end

my_model = MyModel.create!(linked_model: LinkedModel.new)
  • ✅ If you run my_model.destroy then both objects get soft-deleted as you would expect
  • ❌ However if you then subsequently run my_model.really_destroy it does not destroy the associated linked_model.

This is because paranoia tries to access the linked model by running self.send(name). This command will not pick up soft-deleted has_one associations (though it works fine for has_many associations) so some extra code is required in this scenario.

Note the reload in the test is required, as otherwise the version of my_model in memory still links to the LinkedModel.

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.

1 participant