When recursively restoring a has_one relation, Paranoia tries to restore any matching deleted record. It ignores the association scope. This can cause both false positives and false negatives when restoring.
This PR imitates this commit from acts_as_paranoid. I am not sure if intentionally, but that commit introduced scope merging for has_one relations there.
when looking for parent.alpha (or beta) to restore, loading association fails, because there are no undeleted records
lib/paranoia.rb:204 association_data = send(association.name) = nil
the procedure at lib/paranoia.rb:224 ignores association scope and restores the lowest-id record, :gamma
effect: beta was never restored and is nil, gamma was restored incorrectly
I am not sure if reflection.scope is the correct way to recover association's scope, acts_as_paranoid does this differently. It works in AR 5.1-7.1 though.
I have tested this PR in ruby 3.2.2 in rails 7.1.3 and 6.1.7.6. It also does work in 5.1.7 application, but I failed to resolve gems in ruby 2.5.8/2.6.9 (and run the suite)
When recursively restoring a has_one relation, Paranoia tries to restore any matching deleted record. It ignores the association scope. This can cause both false positives and false negatives when restoring.
This PR imitates this commit from acts_as_paranoid. I am not sure if intentionally, but that commit introduced scope merging for has_one relations there.
I am not sure if
reflection.scope
is the correct way to recover association's scope, acts_as_paranoid does this differently. It works in AR 5.1-7.1 though. I have tested this PR in ruby 3.2.2 in rails 7.1.3 and 6.1.7.6. It also does work in 5.1.7 application, but I failed to resolve gems in ruby 2.5.8/2.6.9 (and run the suite)