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.
31 lines
774 B
31 lines
774 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 root_identifier
|
|
p = self
|
|
while p.parent_category.present?
|
|
p = p.parent_category
|
|
end
|
|
p.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
|