-
Notifications
You must be signed in to change notification settings - Fork 11
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
CV2-6041: Verify the relationship target before establishing a new one. #2201
CV2-6041: Verify the relationship target before establishing a new one. #2201
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@melsawy maybe this is a dumb question: but why not have this logic after the if r.nil?
in line 164? Why do we want to check for this in line 161 and then again in 164, but then do something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vasconsaurus the first check against source_id & target_id and also I need to check another case for target_id only to avoid DB validation (unique index for target_id)
I did this before L164 as I need to skip any operation in case there is a relation with same target_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation @melsawy!
app/models/relationship.rb
Outdated
r = Relationship.where(target_id: target_id).where.not(source_id: source_id).last | ||
r = Relationship.where(source_id: source_id, target_id: target_id).where('relationship_type = ?', relationship_type.to_yaml).last unless r.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @melsawy , it's still not clear to me what's the idea here (and I think that we need a comment in this code to explain it, like we had in the other parts of this method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and added more comments
Code Climate has analyzed commit 0f1a5a2 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (100% is the threshold). This pull request will bring the total coverage in the repository to 100.0% (0.0% change). View more on Code Climate. |
…e. (#2201) * CV2-6041: check relationship target before creating new one * CV2-6041: apply PR comments
Description
Verify the relationship target before establishing a new one to prevent triggering errors due to database unique validation.
References: CV2-6041
How has this been tested?
Re-run automated tests.
Checklist