mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 21:45:23 +02:00
Improve category level limit validation
This commit is contained in:
parent
d428a1f954
commit
797cf3c065
1 changed files with 5 additions and 1 deletions
|
@ -91,6 +91,10 @@ class Category < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parent?
|
||||||
|
subcategories.any?
|
||||||
|
end
|
||||||
|
|
||||||
def subcategory?
|
def subcategory?
|
||||||
parent.present?
|
parent.present?
|
||||||
end
|
end
|
||||||
|
@ -121,7 +125,7 @@ class Category < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
def category_level_limit
|
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")
|
errors.add(:parent, "can't have more than 2 levels of subcategories")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue