refactor: simplify region creation and update code attribute
- Change from find_or_initialize_by to find_or_create_by for regions. - Set region code to the name instead of nil. This refactor reduces complexity in how regions are created and ensures the code attribute is properly populated with the region's name, enhancing data consistency.
This commit is contained in:
parent
97330fef91
commit
29ad6be241
@ -22,14 +22,12 @@ namespace :geo do
|
||||
count = 1
|
||||
|
||||
regions.each do |data|
|
||||
region = Region.find_or_initialize_by(name: data["name"]) do |r|
|
||||
end
|
||||
region = Region.find_or_create_by(name: data["name"])
|
||||
puts "Sync Regions[#{count}/#{sum}]: [#{region.name}]"
|
||||
count += 1
|
||||
|
||||
region.update(
|
||||
name: data["name"],
|
||||
code: nil,
|
||||
code: data["name"],
|
||||
translations: data["translations"],
|
||||
flag: data["flag"] || true,
|
||||
wiki_data_id: data["wikiDataId"]
|
||||
|
Loading…
Reference in New Issue
Block a user