You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 have a piece of code on parent model
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
The text was updated successfully, but these errors were encountered: