You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
826 B
34 lines
826 B
class Category < ApplicationRecord
|
|
|
|
has_many :questions
|
|
belongs_to :parent_category, class_name: 'Category', foreign_key: :parent_category_id
|
|
has_many :child_categories, class_name: 'Category', foreign_key: :parent_category_id
|
|
has_many :school_categories
|
|
|
|
validates :name, presence: true
|
|
|
|
scope :for_parent, -> (category=nil) { where(parent_category_id: category.try(:id)) }
|
|
|
|
def path
|
|
p = self
|
|
items = [p]
|
|
items << p while (p = p.try(:parent_category))
|
|
items.uniq.compact.reverse
|
|
end
|
|
|
|
def root_identifier
|
|
path.first.name.downcase.gsub(/\s/, '-')
|
|
end
|
|
|
|
def root_index
|
|
[
|
|
"teachers-and-the-teaching-environment",
|
|
"school-culture",
|
|
"resources",
|
|
"indicators-of-academic-learning",
|
|
"character-and-wellbeing-outcomes"
|
|
].index(root_identifier)
|
|
end
|
|
|
|
end
|