Skip to content
Snippets Groups Projects
Commit 9e686fb7 authored by ArtOfCode-'s avatar ArtOfCode-
Browse files

Disallow self-parenting

parent 7c003207
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ class Tag < ApplicationRecord
validates :excerpt, length: { maximum: 600 }, allow_blank: true
validates :wiki_markdown, length: { maximum: 30000 }, allow_blank: true
validate :parent_not_self
validate :parent_not_own_child
def self.search(term)
......@@ -23,6 +24,13 @@ class Tag < ApplicationRecord
private
def parent_not_self
return unless parent_id.present?
if parent_id == id
errors.add(:base, 'A tag cannot be its own parent.')
end
end
def parent_not_own_child
return unless parent_id.present?
if all_children.include? parent_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment