[#3196] Make TypeDeChamp#options compatible with raw JSON
instead of YAML inside a JSON string. We still need to support the YAML form until the data has been migrated
This commit is contained in:
parent
06f3143e61
commit
36d6a43084
1 changed files with 19 additions and 1 deletions
|
@ -37,7 +37,25 @@ class TypeDeChamp < ApplicationRecord
|
||||||
belongs_to :parent, class_name: 'TypeDeChamp'
|
belongs_to :parent, class_name: 'TypeDeChamp'
|
||||||
has_many :types_de_champ, foreign_key: :parent_id, class_name: 'TypeDeChamp', dependent: :destroy
|
has_many :types_de_champ, foreign_key: :parent_id, class_name: 'TypeDeChamp', dependent: :destroy
|
||||||
|
|
||||||
store :options, accessors: [:cadastres, :quartiers_prioritaires, :parcelles_agricoles]
|
store_accessor :options, :cadastres, :quartiers_prioritaires, :parcelles_agricoles
|
||||||
|
|
||||||
|
# TODO start: remove after migrating `options` column to (non YAML encoded) JSON
|
||||||
|
class MaybeYaml
|
||||||
|
def load(options)
|
||||||
|
if options.is_a?(String)
|
||||||
|
YAML.safe_load(options, [ActiveSupport::HashWithIndifferentAccess])
|
||||||
|
else
|
||||||
|
options
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def dump(options)
|
||||||
|
options
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
serialize :options, MaybeYaml.new
|
||||||
|
# TODO stop: remove after migrating `options` column to (non YAML encoded) JSON
|
||||||
|
|
||||||
after_initialize :set_dynamic_type
|
after_initialize :set_dynamic_type
|
||||||
after_create :populate_stable_id
|
after_create :populate_stable_id
|
||||||
|
|
Loading…
Reference in a new issue