diff --git a/app/models/category.rb b/app/models/category.rb index ebeadbf9..2a4e2799 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -91,6 +91,10 @@ class Category < ApplicationRecord end end + def parent? + subcategories.any? + end + def subcategory? parent.present? end @@ -121,7 +125,7 @@ class Category < ApplicationRecord private def category_level_limit - if subcategory? && parent.subcategory? + if (subcategory? && parent.subcategory?) || (parent? && subcategory?) errors.add(:parent, "can't have more than 2 levels of subcategories") end end