add habtm between procedures and zones
This commit is contained in:
parent
5a6dddc6d5
commit
bffd9d61a9
4 changed files with 22 additions and 2 deletions
|
@ -103,6 +103,7 @@ class Procedure < ApplicationRecord
|
|||
belongs_to :replaced_by_procedure, -> { with_discarded }, inverse_of: :replaced_procedures, class_name: "Procedure", optional: true
|
||||
belongs_to :service, optional: true
|
||||
belongs_to :zone, optional: true
|
||||
has_and_belongs_to_many :zones
|
||||
|
||||
def active_dossier_submitted_message
|
||||
published_dossier_submitted_message || draft_dossier_submitted_message
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
class Zone < ApplicationRecord
|
||||
validates :acronym, presence: true, uniqueness: true
|
||||
has_many :labels, -> { order(designated_on: :desc) }, class_name: 'ZoneLabel', inverse_of: :zone
|
||||
has_many :procedures, -> { order(published_at: :desc) }, inverse_of: :zone
|
||||
has_and_belongs_to_many :procedures, -> { order(published_at: :desc) }, inverse_of: :zone
|
||||
|
||||
def current_label
|
||||
labels.first.name
|
||||
|
|
10
db/migrate/20221006190110_create_procedures_and_zones.rb
Normal file
10
db/migrate/20221006190110_create_procedures_and_zones.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class CreateProceduresAndZones < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :procedures_zones, id: false do |t|
|
||||
t.belongs_to :procedure
|
||||
t.belongs_to :zone
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
11
db/schema.rb
11
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_10_05_145646) do
|
||||
ActiveRecord::Schema.define(version: 2022_10_06_190110) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
|
@ -685,6 +685,15 @@ ActiveRecord::Schema.define(version: 2022_10_05_145646) do
|
|||
t.index ["zone_id"], name: "index_procedures_on_zone_id"
|
||||
end
|
||||
|
||||
create_table "procedures_zones", id: false, force: :cascade do |t|
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.bigint "procedure_id"
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.bigint "zone_id"
|
||||
t.index ["procedure_id"], name: "index_procedures_zones_on_procedure_id"
|
||||
t.index ["zone_id"], name: "index_procedures_zones_on_zone_id"
|
||||
end
|
||||
|
||||
create_table "received_mails", id: :serial, force: :cascade do |t|
|
||||
t.text "body"
|
||||
t.datetime "created_at", null: false
|
||||
|
|
Loading…
Reference in a new issue