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.
27 lines
725 B
27 lines
725 B
# frozen_string_literal: true
|
|
|
|
class School < ApplicationRecord
|
|
belongs_to :district
|
|
|
|
has_many :survey_item_responses, dependent: :delete_all
|
|
|
|
validates :name, presence: true
|
|
|
|
scope :alphabetic, -> { order(name: :asc) }
|
|
scope :school_hash, -> { all.map { |school| [school.dese_id, school] }.to_h }
|
|
|
|
include FriendlyId
|
|
friendly_id :name, use: [:slugged]
|
|
|
|
def self.find_by_district_code_and_school_code(district_code, school_code)
|
|
School
|
|
.joins(:district)
|
|
.where(districts: { qualtrics_code: district_code })
|
|
.find_by_qualtrics_code(school_code)
|
|
end
|
|
|
|
def grades(academic_year:)
|
|
Respondent.find_by(school: self, academic_year:)&.enrollment_by_grade&.keys || (-1..12).to_a
|
|
end
|
|
end
|