Hey Ron
I think you could create the indexer fields by iterating over the stored values and adding the booleans 'dynamically'. Kinda like so
if doc['primary_type'] == 'accession'
if record['record']['dynamaterial_types']
record['record']['dynamaterial_types'].each do |dmt|
doc["#{dmt}_u_ubool"] = true
end
end
end
For the db CRUD in the dynamaterial_types model, you'd probably want something along the lines of:
def valid_dmts
# return valid enum values for dyn materials
# something like
dyn_mat_enum_id = Enumerations.filter(:name => dyn_mat_enum_name).get(:id)
allowed = []
EnumerationValues.filter(:enumeration_id => dyn_mat_enum_id).each do |dmt|
allowed << dmt[:value]
end
allowed
end
def validate_dmt_list(dmts)
allowed = valid_dmts
dmts.keep_if { |element| allowed.include?(element) }
dmts
end
def self.create_from_json(json, opts = {})
allowed_dmts = validate_dmt_list(json.dmt_list)
super(json, opts.merge('dmt_list' => JSON(json.allowed_dmts || [])))
end
def update_from_json(json, opts = {}, apply_nested_records = true)
allowed_dmts = validate_dmt_list(json.dmt_list)
super(json, opts.merge('dmt_list' => JSON(json.allowed_dmts || [])))
end
def self.sequel_to_jsonmodel(objs, opts = {})
jsons = super
jsons.zip(objs).each do |json, obj|
json['dmt_list'] = ASUtils.json_parse(obj.dmt_list)
end
end
Bit handwavy, but I think that's the way I'd approach this at first.
jds