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

Issue with restrict_with_error #455

Open
vidivalianto opened this issue Oct 22, 2018 · 0 comments
Open

Issue with restrict_with_error #455

vidivalianto opened this issue Oct 22, 2018 · 0 comments
Labels

Comments

@vidivalianto
Copy link

vidivalianto commented Oct 22, 2018

i have a piece of code on parent model

class Parent < ApplicationRecord
  has_many :son_models, dependent: :destroy
  has_many :daughter_models, dependent: :restrict_with_error
end

the issue starts when i have a parent record with associated records on son_models and daughter_models. when i try to delete that parent record, an error kicks in because i have record on daughter_models and delete action fails. However, my son_models records remain deleted even after the error. This issue surely will cause an issue in a model with multiple nested attributes as some values are missing after a failed attempt to delete the record.
At the moment, i can prevent this by swapping has_many relationship to make sure it checks the restrict_with_error first and it's hacky and tiring if i need to sort the relation every time i specify a new one.

I make a dummy rails app with spec to show the issue. the link is https://github.com/vidivalianto/paranoia-error

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

No branches or pull requests

2 participants