summaryrefslogtreecommitdiff
path: root/app/models/issue_link.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/issue_link.rb')
-rw-r--r--app/models/issue_link.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/issue_link.rb b/app/models/issue_link.rb
index 9740b009396..5448ebdf50b 100644
--- a/app/models/issue_link.rb
+++ b/app/models/issue_link.rb
@@ -10,6 +10,7 @@ class IssueLink < ApplicationRecord
validates :target, presence: true
validates :source, uniqueness: { scope: :target_id, message: 'is already related' }
validate :check_self_relation
+ validate :check_opposite_relation
scope :for_source_issue, ->(issue) { where(source_id: issue.id) }
scope :for_target_issue, ->(issue) { where(target_id: issue.id) }
@@ -33,6 +34,14 @@ class IssueLink < ApplicationRecord
errors.add(:source, 'cannot be related to itself')
end
end
+
+ def check_opposite_relation
+ return unless source && target
+
+ if IssueLink.find_by(source: target, target: source)
+ errors.add(:source, 'is already related to this issue')
+ end
+ end
end
IssueLink.prepend_if_ee('EE::IssueLink')