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

CV2-6141: Update options for existing relationship #2234

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/bot/alegre.rb
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def self.relationship_model_not_allowed(relationship_model)

def self.report_exception_if_bad_relationship(relationship, pm_id_scores, relationship_type)
if relationship.model.nil? || relationship.weight.nil? || relationship.source_field.nil? || relationship.target_field.nil? || self.relationship_model_not_allowed(relationship.model)
CheckSentry.notify(Bot::Alegre::Error.new("[Alegre] Bad relationship was stored without required metadata"), **{trace: Thread.current.backtrace.join("\n"), relationship: relationship.attributes, relationship_type: relationship_type, pm_id_scores: pm_id_scores})
CheckSentry.notify(Bot::Alegre::Error.new("[Alegre] Bad relationship with ID [#{relationship.id}] was stored without required metadata"), **{trace: Thread.current.backtrace.join("\n"), relationship: relationship.attributes, relationship_type: relationship_type, pm_id_scores: pm_id_scores})
end
end

Expand Down
7 changes: 7 additions & 0 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ def create_or_update_parent_id
def self.create_unless_exists(source_id, target_id, relationship_type, options = {})
# Verify that the target is not part of another source; in this case, we should return the existing relationship.
r = Relationship.where(target_id: target_id).where.not(source_id: source_id).last
# should update options if exists and at least on field is blank
if !r.nil? && !options.blank? && r.model.blank?
options.each do |key, value|
r.send("#{key}=", value) if r.respond_to?("#{key}=")
end
r.save!
end
return r unless r.nil?
# otherwise we should get the existing relationship based on source, target and type
r = Relationship.where(source_id: source_id, target_id: target_id).where('relationship_type = ?', relationship_type.to_yaml).last
Expand Down
Loading