chore: update schools and districts to correct association between them

This commit is contained in:
Nelson Jovel 2024-01-05 12:46:51 -08:00
parent 3093d9236a
commit 0f525cf2e8
10 changed files with 12 additions and 28 deletions

View file

@ -1,8 +1,6 @@
module Dashboard module Dashboard
class District < ApplicationRecord class District < ApplicationRecord
self.table_name = "districts" has_many :schools, class_name: "School", foreign_key: :id
has_many :schools, class_name: "Dashboard::School"
has_many :schools, class_name: "Dashboard::School"
validates :name, presence: true validates :name, presence: true
@ -17,3 +15,4 @@ module Dashboard
end end
end end
end end

View file

@ -1,4 +0,0 @@
module Dashboard
class Example < ApplicationRecord
end
end

View file

@ -1,11 +1,10 @@
module Dashboard module Dashboard
class School < ApplicationRecord class School < ApplicationRecord
self.table_name = "schools" belongs_to :district, class_name: "District", foreign_key: :dashboard_district_id
belongs_to :district, class_name: "District", primary_key: :id
has_many :dashboard_survey_item_responses, dependent: :delete_all # has_many :dashboard_survey_item_responses, dependent: :delete_all
# validates :name, presence: true validates :name, presence: true
scope :alphabetic, -> { order(name: :asc) } scope :alphabetic, -> { order(name: :asc) }
scope :school_hash, -> { all.map { |school| [school.dese_id, school] }.to_h } scope :school_hash, -> { all.map { |school| [school.dese_id, school] }.to_h }

View file

@ -1,10 +0,0 @@
class CreateDashboardExamples < ActiveRecord::Migration[7.1]
def change
create_table :dashboard_examples do |t|
t.string :text
t.text :body
t.timestamps
end
end
end

View file

@ -1,6 +1,6 @@
class CreateDashboardDistricts < ActiveRecord::Migration[7.1] class CreateDashboardDistricts < ActiveRecord::Migration[7.1]
def change def change
create_table :districts do |t| create_table :dashboard_districts do |t|
t.string :name t.string :name
t.string :slug t.string :slug
t.integer :qualtrics_code t.integer :qualtrics_code

View file

@ -1,8 +1,8 @@
class CreateDashboardSchools < ActiveRecord::Migration[7.1] class CreateDashboardSchools < ActiveRecord::Migration[7.1]
def change def change
create_table :schools do |t| create_table :dashboard_schools do |t|
t.string :name t.string :name
t.references :district, null: false, foreign_key: true t.references :dashboard_district, null: false, foreign_key: true
t.text :description t.text :description
t.string :slug t.string :slug
t.integer :qualtrics_code t.integer :qualtrics_code

View file

@ -2,7 +2,7 @@ class CreateDashboardAdminDataValues < ActiveRecord::Migration[7.1]
def change def change
create_table :dashboard_admin_data_values do |t| create_table :dashboard_admin_data_values do |t|
t.float :likert_score t.float :likert_score
t.references :school, null: false, foreign_key: true t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_admin_data_item, null: false, foreign_key: true t.references :dashboard_admin_data_item, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true

View file

@ -1,7 +1,7 @@
class CreateDashboardRespondents < ActiveRecord::Migration[7.1] class CreateDashboardRespondents < ActiveRecord::Migration[7.1]
def change def change
create_table :dashboard_respondents do |t| create_table :dashboard_respondents do |t|
t.references :school, null: false, foreign_key: true t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true
t.integer :total_students t.integer :total_students
t.float :total_teachers t.float :total_teachers

View file

@ -2,7 +2,7 @@ class CreateDashboardResponseRates < ActiveRecord::Migration[7.1]
def change def change
create_table :dashboard_response_rates do |t| create_table :dashboard_response_rates do |t|
t.references :dashboard_subcategory, null: false, foreign_key: true t.references :dashboard_subcategory, null: false, foreign_key: true
t.references :school, null: false, foreign_key: true t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true
t.float :school_response_rate t.float :school_response_rate
t.float :teacher_response_rate t.float :teacher_response_rate

View file

@ -2,7 +2,7 @@ class CreateDashboardSurveyItemResponses < ActiveRecord::Migration[7.1]
def change def change
create_table :dashboard_survey_item_responses do |t| create_table :dashboard_survey_item_responses do |t|
t.integer :likert_score t.integer :likert_score
t.references :school, null: false, foreign_key: true t.references :dashboard_school, null: false, foreign_key: true
t.references :dashboard_survey_item, null: false, foreign_key: true t.references :dashboard_survey_item, null: false, foreign_key: true
t.references :dashboard_academic_year, null: false, foreign_key: true t.references :dashboard_academic_year, null: false, foreign_key: true
t.references :dashboard_student, foreign_key: true t.references :dashboard_student, foreign_key: true