From 09c37435adaae2bb3e5247fe8dc291e635e4e508 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 6 Dec 2021 21:03:26 +0100 Subject: [PATCH] feat(procedure_revision_types_de_champ): add parent_id --- app/models/procedure_revision_type_de_champ.rb | 3 +++ ...1808_add_parent_id_to_procedure_revision_type_de_champ.rb | 5 +++++ db/schema.rb | 5 ++++- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20210630101808_add_parent_id_to_procedure_revision_type_de_champ.rb diff --git a/app/models/procedure_revision_type_de_champ.rb b/app/models/procedure_revision_type_de_champ.rb index 6859d1884..c50951ddd 100644 --- a/app/models/procedure_revision_type_de_champ.rb +++ b/app/models/procedure_revision_type_de_champ.rb @@ -6,6 +6,7 @@ # position :integer not null # created_at :datetime not null # updated_at :datetime not null +# parent_id :bigint # revision_id :bigint not null # type_de_champ_id :bigint not null # @@ -13,6 +14,8 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord belongs_to :revision, class_name: 'ProcedureRevision' belongs_to :type_de_champ + belongs_to :parent, class_name: 'ProcedureRevisionTypeDeChamp', optional: true + has_many :revision_types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: :parent, dependent: :destroy scope :ordered, -> { order(:position) } scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) } scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) } diff --git a/db/migrate/20210630101808_add_parent_id_to_procedure_revision_type_de_champ.rb b/db/migrate/20210630101808_add_parent_id_to_procedure_revision_type_de_champ.rb new file mode 100644 index 000000000..66851c8da --- /dev/null +++ b/db/migrate/20210630101808_add_parent_id_to_procedure_revision_type_de_champ.rb @@ -0,0 +1,5 @@ +class AddParentIdToProcedureRevisionTypeDeChamp < ActiveRecord::Migration[6.1] + def change + add_belongs_to :procedure_revision_types_de_champ, :parent, index: true, foreign_key: { to_table: :procedure_revision_types_de_champ } + end +end diff --git a/db/schema.rb b/db/schema.rb index 2ea7addb4..0b9662e45 100644 --- a/db/schema.rb +++ b/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: 2021_12_01_135804) do +ActiveRecord::Schema.define(version: 2021_12_02_135804) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -581,6 +581,8 @@ ActiveRecord::Schema.define(version: 2021_12_01_135804) do t.integer "position", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "parent_id" + t.index ["parent_id"], name: "index_procedure_revision_types_de_champ_on_parent_id" t.index ["revision_id"], name: "index_procedure_revision_types_de_champ_on_revision_id" t.index ["type_de_champ_id"], name: "index_procedure_revision_types_de_champ_on_type_de_champ_id" end @@ -865,6 +867,7 @@ ActiveRecord::Schema.define(version: 2021_12_01_135804) do add_foreign_key "initiated_mails", "procedures" add_foreign_key "merge_logs", "users" add_foreign_key "procedure_presentations", "assign_tos" + add_foreign_key "procedure_revision_types_de_champ", "procedure_revision_types_de_champ", column: "parent_id" add_foreign_key "procedure_revision_types_de_champ", "procedure_revisions", column: "revision_id" add_foreign_key "procedure_revision_types_de_champ", "types_de_champ" add_foreign_key "procedure_revisions", "procedures"