From 0f525cf2e824d1d1774d93df69a079b18154e3f2 Mon Sep 17 00:00:00 2001 From: Nelson Jovel Date: Fri, 5 Jan 2024 12:46:51 -0800 Subject: [PATCH] chore: update schools and districts to correct association between them --- app/models/dashboard/district.rb | 5 ++--- app/models/dashboard/example.rb | 4 ---- app/models/dashboard/school.rb | 7 +++---- db/migrate/20231223040511_create_dashboard_examples.rb | 10 ---------- .../20240104173931_create_dashboard_districts.rb | 2 +- db/migrate/20240104174053_create_dashboard_schools.rb | 4 ++-- ...0240104174331_create_dashboard_admin_data_values.rb | 2 +- .../20240104181617_create_dashboard_respondents.rb | 2 +- .../20240104181856_create_dashboard_response_rates.rb | 2 +- ...104192128_create_dashboard_survey_item_responses.rb | 2 +- 10 files changed, 12 insertions(+), 28 deletions(-) delete mode 100644 app/models/dashboard/example.rb delete mode 100644 db/migrate/20231223040511_create_dashboard_examples.rb diff --git a/app/models/dashboard/district.rb b/app/models/dashboard/district.rb index 13c613a..a88545a 100644 --- a/app/models/dashboard/district.rb +++ b/app/models/dashboard/district.rb @@ -1,8 +1,6 @@ module Dashboard class District < ApplicationRecord - self.table_name = "districts" - has_many :schools, class_name: "Dashboard::School" - has_many :schools, class_name: "Dashboard::School" + has_many :schools, class_name: "School", foreign_key: :id validates :name, presence: true @@ -17,3 +15,4 @@ module Dashboard end end end + diff --git a/app/models/dashboard/example.rb b/app/models/dashboard/example.rb deleted file mode 100644 index 9f42183..0000000 --- a/app/models/dashboard/example.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Dashboard - class Example < ApplicationRecord - end -end diff --git a/app/models/dashboard/school.rb b/app/models/dashboard/school.rb index f0379af..4e3d064 100644 --- a/app/models/dashboard/school.rb +++ b/app/models/dashboard/school.rb @@ -1,11 +1,10 @@ module Dashboard class School < ApplicationRecord - self.table_name = "schools" - belongs_to :district, class_name: "District", primary_key: :id + belongs_to :district, class_name: "District", foreign_key: :dashboard_district_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 :school_hash, -> { all.map { |school| [school.dese_id, school] }.to_h } diff --git a/db/migrate/20231223040511_create_dashboard_examples.rb b/db/migrate/20231223040511_create_dashboard_examples.rb deleted file mode 100644 index 0108ae7..0000000 --- a/db/migrate/20231223040511_create_dashboard_examples.rb +++ /dev/null @@ -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 diff --git a/db/migrate/20240104173931_create_dashboard_districts.rb b/db/migrate/20240104173931_create_dashboard_districts.rb index e3b14cc..e494169 100644 --- a/db/migrate/20240104173931_create_dashboard_districts.rb +++ b/db/migrate/20240104173931_create_dashboard_districts.rb @@ -1,6 +1,6 @@ class CreateDashboardDistricts < ActiveRecord::Migration[7.1] def change - create_table :districts do |t| + create_table :dashboard_districts do |t| t.string :name t.string :slug t.integer :qualtrics_code diff --git a/db/migrate/20240104174053_create_dashboard_schools.rb b/db/migrate/20240104174053_create_dashboard_schools.rb index 30cd565..45814c5 100644 --- a/db/migrate/20240104174053_create_dashboard_schools.rb +++ b/db/migrate/20240104174053_create_dashboard_schools.rb @@ -1,8 +1,8 @@ class CreateDashboardSchools < ActiveRecord::Migration[7.1] def change - create_table :schools do |t| + create_table :dashboard_schools do |t| t.string :name - t.references :district, null: false, foreign_key: true + t.references :dashboard_district, null: false, foreign_key: true t.text :description t.string :slug t.integer :qualtrics_code diff --git a/db/migrate/20240104174331_create_dashboard_admin_data_values.rb b/db/migrate/20240104174331_create_dashboard_admin_data_values.rb index cb52616..f9ec684 100644 --- a/db/migrate/20240104174331_create_dashboard_admin_data_values.rb +++ b/db/migrate/20240104174331_create_dashboard_admin_data_values.rb @@ -2,7 +2,7 @@ class CreateDashboardAdminDataValues < ActiveRecord::Migration[7.1] def change create_table :dashboard_admin_data_values do |t| 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_academic_year, null: false, foreign_key: true diff --git a/db/migrate/20240104181617_create_dashboard_respondents.rb b/db/migrate/20240104181617_create_dashboard_respondents.rb index 2092e1a..5c54156 100644 --- a/db/migrate/20240104181617_create_dashboard_respondents.rb +++ b/db/migrate/20240104181617_create_dashboard_respondents.rb @@ -1,7 +1,7 @@ class CreateDashboardRespondents < ActiveRecord::Migration[7.1] def change 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.integer :total_students t.float :total_teachers diff --git a/db/migrate/20240104181856_create_dashboard_response_rates.rb b/db/migrate/20240104181856_create_dashboard_response_rates.rb index 2195cc5..cb3ef71 100644 --- a/db/migrate/20240104181856_create_dashboard_response_rates.rb +++ b/db/migrate/20240104181856_create_dashboard_response_rates.rb @@ -2,7 +2,7 @@ class CreateDashboardResponseRates < ActiveRecord::Migration[7.1] def change create_table :dashboard_response_rates do |t| 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.float :school_response_rate t.float :teacher_response_rate diff --git a/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb b/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb index 57efcff..b2d46d7 100644 --- a/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb +++ b/db/migrate/20240104192128_create_dashboard_survey_item_responses.rb @@ -2,7 +2,7 @@ class CreateDashboardSurveyItemResponses < ActiveRecord::Migration[7.1] def change create_table :dashboard_survey_item_responses do |t| 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_academic_year, null: false, foreign_key: true t.references :dashboard_student, foreign_key: true