diff --git a/app/controllers/new_administrateur/types_de_champ_controller.rb b/app/controllers/new_administrateur/types_de_champ_controller.rb index b88cb1642..ea7023757 100644 --- a/app/controllers/new_administrateur/types_de_champ_controller.rb +++ b/app/controllers/new_administrateur/types_de_champ_controller.rb @@ -44,7 +44,6 @@ module NewAdministrateur { type_de_champ: type_de_champ.as_json( except: [ - :id, :created_at, :options, :order_place, @@ -64,7 +63,7 @@ module NewAdministrateur :piece_justificative_template_url, :quartiers_prioritaires ] - ).merge(id: TypeDeChamp.format_stable_id(type_de_champ.stable_id)) + ) } end diff --git a/app/models/champ.rb b/app/models/champ.rb index b4231596c..a4f5b35ad 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -48,7 +48,13 @@ class Champ < ApplicationRecord scope :private_only, -> { where(private: true) } scope :ordered, -> { includes(:type_de_champ).order(:row, 'types_de_champ.order_place') } scope :public_ordered, -> { public_only.joins(dossier: { revision: :revision_types_de_champ }).where('procedure_revision_types_de_champ.type_de_champ_id = champs.type_de_champ_id').order(:position) } - scope :private_ordered, -> { private_only.joins(dossier: { revision: :revision_types_de_champ_private }).where('procedure_revision_types_de_champ.type_de_champ_id = champs.type_de_champ_id').order(:position) } + # we need to do private champs order as manual join to avoid conflicting join names + scope :private_ordered, -> do + private_only.joins('INNER JOIN types_de_champ types_de_champ_private + ON types_de_champ_private.id = champs.type_de_champ_id AND types_de_champ_private.private = true + INNER JOIN procedure_revision_types_de_champ procedure_revision_types_de_champ_private + ON procedure_revision_types_de_champ_private.type_de_champ_id = types_de_champ_private.id').order(:position) + end scope :root, -> { where(parent_id: nil) } diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index e0ff6990d..a3ee48103 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -2,20 +2,19 @@ # # Table name: types_de_champ # -# id :integer not null, primary key -# description :text -# libelle :string -# mandatory :boolean default(FALSE) -# options :jsonb -# order_place :integer -# private :boolean default(FALSE), not null -# type_champ :string -# created_at :datetime -# updated_at :datetime -# parent_id :bigint -# procedure_id :integer -# revision_id :bigint -# stable_id :bigint +# id :integer not null, primary key +# description :text +# libelle :string +# mandatory :boolean default(FALSE) +# options :jsonb +# order_place :integer +# private :boolean default(FALSE), not null +# type_champ :string +# created_at :datetime +# updated_at :datetime +# parent_id :bigint +# revision_id :bigint +# stable_id :bigint # class TypeDeChamp < ApplicationRecord self.ignored_columns = ['procedure_id'] @@ -304,7 +303,7 @@ class TypeDeChamp < ApplicationRecord def read_attribute_for_serialization(name) if name == 'id' - self.class.format_stable_id(stable_id) + stable_id else super end @@ -317,15 +316,11 @@ class TypeDeChamp < ApplicationRecord # This is only needed for a clean migration without downtime. We want to ensure # that if editor send a simple id because it was loaded before deployment # we would still do the right thing. - def self.format_stable_id(stable_id) - "stable:#{stable_id}" - end - def self.to_stable_id(id_or_stable_id) if id_or_stable_id.to_s =~ /^stable:/ id_or_stable_id.to_s.gsub(/^stable:/, '') else - find(id_or_stable_id).stable_id + id_or_stable_id end end diff --git a/db/migrate/20200902103047_remove_type_de_champ_procedure_id.rb b/db/migrate/20200902103047_remove_type_de_champ_procedure_id.rb new file mode 100644 index 000000000..8a4f5fba7 --- /dev/null +++ b/db/migrate/20200902103047_remove_type_de_champ_procedure_id.rb @@ -0,0 +1,5 @@ +class RemoveTypeDeChampProcedureId < ActiveRecord::Migration[6.0] + def change + remove_column :types_de_champ, :procedure_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 985446dae..2c5243048 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: 2020_08_19_153016) do +ActiveRecord::Schema.define(version: 2020_09_02_103047) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -611,7 +611,6 @@ ActiveRecord::Schema.define(version: 2020_08_19_153016) do t.string "libelle" t.string "type_champ" t.integer "order_place" - t.integer "procedure_id" t.text "description" t.boolean "mandatory", default: false t.boolean "private", default: false, null: false @@ -623,7 +622,6 @@ ActiveRecord::Schema.define(version: 2020_08_19_153016) do t.bigint "revision_id" t.index ["parent_id"], name: "index_types_de_champ_on_parent_id" t.index ["private"], name: "index_types_de_champ_on_private" - t.index ["procedure_id"], name: "index_types_de_champ_on_procedure_id" t.index ["revision_id"], name: "index_types_de_champ_on_revision_id" t.index ["stable_id"], name: "index_types_de_champ_on_stable_id" end