Browse Source

added foreign key and cascading delete for organisations to users/logs

pull/740/head
Ted 3 years ago committed by JG
parent
commit
0f77d13df7
  1. 10
      app/models/organisation.rb
  2. 8
      db/schema.rb

10
app/models/organisation.rb

@ -1,11 +1,11 @@
class Organisation < ApplicationRecord
has_many :users
has_many :owned_case_logs, class_name: "CaseLog", foreign_key: "owning_organisation_id"
has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id"
has_many :users, dependent: :destroy
has_many :owned_case_logs, class_name: "CaseLog", foreign_key: "owning_organisation_id", dependent: :destroy
has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id", dependent: :destroy
has_many :data_protection_confirmations
has_many :organisation_rent_periods
has_many :owned_schemes, class_name: "Scheme", foreign_key: "owning_organisation_id"
has_many :managed_schemes, class_name: "Scheme", foreign_key: "managing_organisation_id"
has_many :owned_schemes, class_name: "Scheme", foreign_key: "stock_owning_organisation_id", dependent: :destroy
has_many :managed_schemes, class_name: "Scheme", dependent: :destroy
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param) }

8
db/schema.rb

@ -191,19 +191,21 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_12_143943) do
t.integer "joint"
t.bigint "created_by_id"
t.integer "illness_type_0"
t.integer "retirement_value_check"
t.integer "tshortfall_known"
t.integer "sheltered"
t.integer "retirement_value_check"
t.integer "pregnancy_value_check"
t.integer "hhtype"
t.integer "new_old"
t.integer "vacdays"
t.bigint "scheme_id"
t.bigint "location_id"
t.bigint "organisations_id"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id"
t.index ["location_id"], name: "index_case_logs_on_location_id"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true
t.index ["organisations_id"], name: "index_case_logs_on_organisations_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
t.index ["scheme_id"], name: "index_case_logs_on_scheme_id"
end
@ -359,10 +361,12 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_12_143943) do
t.datetime "confirmed_at", precision: nil
t.datetime "confirmation_sent_at", precision: nil
t.string "unconfirmed_email"
t.bigint "organisations_id"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["encrypted_otp_secret_key"], name: "index_users_on_encrypted_otp_secret_key", unique: true
t.index ["organisation_id"], name: "index_users_on_organisation_id"
t.index ["organisations_id"], name: "index_users_on_organisations_id"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
end
@ -378,8 +382,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_12_143943) do
end
add_foreign_key "case_logs", "locations"
add_foreign_key "case_logs", "organisations", column: "organisations_id"
add_foreign_key "case_logs", "schemes"
add_foreign_key "locations", "schemes"
add_foreign_key "schemes", "organisations", column: "managing_organisation_id"
add_foreign_key "schemes", "organisations", column: "owning_organisation_id"
add_foreign_key "users", "organisations", column: "organisations_id"
end

Loading…
Cancel
Save