WIP: Update the parent table to hold a reference to a language

Update the data uploader script to read the language from the csv and update the language information for any parent items that already exist (or create database entries if none already exist)
This commit is contained in:
rebuilt 2025-04-15 15:03:32 -07:00
parent a48a2b1d7a
commit 446b3b1096
11 changed files with 182 additions and 23 deletions

30
app/models/language.rb Normal file
View file

@ -0,0 +1,30 @@
class Language < ApplicationRecord
scope :by_designation, -> { all.map { |language| [language.designation, language] }.to_h }
has_many :parents, dependent: :nullify
include FriendlyId
friendly_id :designation, use: [:slugged]
def self.to_designation(language)
return "Unknown" if language.blank?
case language
in /^1$|^1[^0]/i
"English"
in /^2$/i
"Portuguese"
in /^3$/i
"Spanish"
in /^99$|^100$/i
"Unknown"
else
puts "************************************"
puts "******** ERROR **********"
puts ""
puts "Error parsing Language column. '#{language}' is not a known value. Halting execution"
puts ""
puts "************************************"
exit
end
end
end