feat(procedure_revision_types_de_champ): add parent_id

This commit is contained in:
Paul Chavard 2021-12-06 21:03:26 +01:00
parent b83425896d
commit 09c37435ad
3 changed files with 12 additions and 1 deletions

View file

@ -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 }) }

View file

@ -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

View file

@ -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"