Commit bbe9cd8d authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Validates self relation

parent d52237a6
...@@ -5,4 +5,15 @@ class RelatedIssue < ActiveRecord::Base ...@@ -5,4 +5,15 @@ class RelatedIssue < ActiveRecord::Base
validates :issue, presence: true validates :issue, presence: true
validates :related_issue, presence: true validates :related_issue, presence: true
validates :issue, uniqueness: { scope: :related_issue_id, message: 'is already related' } validates :issue, uniqueness: { scope: :related_issue_id, message: 'is already related' }
validate :check_self_relation
private
def check_self_relation
return unless issue || related_issue
if issue == related_issue
errors.add(:issue, 'cannot be related to itself')
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment