Browse Source

Add local authority links

pull/1402/head
Kat 3 years ago
parent
commit
a7e7b04b5b
  1. 3
      app/models/local_authority.rb
  2. 4
      app/models/local_authority_link.rb
  3. 12
      db/migrate/20230309145740_add_local_authority_link.rb
  4. 13
      db/schema.rb

3
app/models/local_authority.rb

@ -1,4 +1,7 @@
class LocalAuthority < ApplicationRecord class LocalAuthority < ApplicationRecord
has_many :local_authority_links, dependent: :destroy
has_many :linked_local_authorities, class_name: "LocalAuthority", through: :local_authority_links
scope :active, ->(date) { where("start_date <= ? AND (end_date IS NULL OR end_date >= ?)", date, date) } scope :active, ->(date) { where("start_date <= ? AND (end_date IS NULL OR end_date >= ?)", date, date) }
scope :england, -> { where("code LIKE ?", "E%") } scope :england, -> { where("code LIKE ?", "E%") }
end end

4
app/models/local_authority_link.rb

@ -0,0 +1,4 @@
class LocalAuthorityLink < ApplicationRecord
belongs_to :local_authority, class_name: "LocalAuthority"
belongs_to :linked_local_authority, class_name: "LocalAuthority"
end

12
db/migrate/20230309145740_add_local_authority_link.rb

@ -0,0 +1,12 @@
class AddLocalAuthorityLink < ActiveRecord::Migration[7.0]
def change
create_table :local_authority_links do |t|
t.references :local_authority
t.references :linked_local_authority
t.timestamps
end
add_foreign_key :local_authority_links, :local_authorities, column: :local_authority_id
add_foreign_key :local_authority_links, :local_authorities, column: :linked_local_authority_id
end
end

13
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do ActiveRecord::Schema[7.0].define(version: 2023_03_09_145740) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -299,6 +299,15 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do
t.index ["code"], name: "index_local_authority_code", unique: true t.index ["code"], name: "index_local_authority_code", unique: true
end end
create_table "local_authority_links", force: :cascade do |t|
t.bigint "local_authority_id"
t.bigint "linked_local_authority_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["linked_local_authority_id"], name: "index_local_authority_links_on_linked_local_authority_id"
t.index ["local_authority_id"], name: "index_local_authority_links_on_local_authority_id"
end
create_table "location_deactivation_periods", force: :cascade do |t| create_table "location_deactivation_periods", force: :cascade do |t|
t.datetime "deactivation_date" t.datetime "deactivation_date"
t.datetime "reactivation_date" t.datetime "reactivation_date"
@ -641,6 +650,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_08_101826) do
add_foreign_key "lettings_logs", "locations" add_foreign_key "lettings_logs", "locations"
add_foreign_key "lettings_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade add_foreign_key "lettings_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade
add_foreign_key "lettings_logs", "schemes" add_foreign_key "lettings_logs", "schemes"
add_foreign_key "local_authority_links", "local_authorities"
add_foreign_key "local_authority_links", "local_authorities", column: "linked_local_authority_id"
add_foreign_key "locations", "schemes" add_foreign_key "locations", "schemes"
add_foreign_key "organisation_relationships", "organisations", column: "child_organisation_id" add_foreign_key "organisation_relationships", "organisations", column: "child_organisation_id"
add_foreign_key "organisation_relationships", "organisations", column: "parent_organisation_id" add_foreign_key "organisation_relationships", "organisations", column: "parent_organisation_id"

Loading…
Cancel
Save