Match has_one direction before deleting rel #1662
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1650
When
relationship_corresponding_rel
matches on the rel class name,it stops on the first match, ignoring the
direction
parameter.When
target_class
represents theto_node
, direction is:in
.When the relationship is a
has_one
/has_many
between a pairof nodes of the same class, the match could find and return
the
to_node
's:out
association first, causingdelete_reverse_has_one_relationship
to delete it.Checking the direction first prevents that.
Sadly, I worked through #1660 before seeing #1650 and that I had reached the same basic conclusion, only factoring the fix slightly differently than the OP proposed.
Test runs
I added 4 examples—2 simply show that the 'setup' in the 'real' examples works as expected. The other 2 (really the same example but under both
creates_unique :all
andcreates_unique :none
) show the problem.Before
1907 examples, 0 failures, 5 pending
After
Without the fix
With the fix
1911 examples, 0 failures, 5 pending