fix: correct subregion initialization by name

- Change the method of finding or initializing subregions to use
  the name attribute instead of the id.
- This improves accuracy when synchronizing subregion data, as it
  ensures that subregions are correctly matched by name.
- Eliminates potential issues with duplicate IDs if they happen
  to be reused across different data sources.
This commit is contained in:
songtianlun 2025-02-10 17:21:29 +08:00
parent bafb889144
commit e774b3e736

View File

@ -42,8 +42,7 @@ namespace :geo do
count = 1
subregions.each do |data|
subregion = Subregion.find_or_initialize_by(id: data["id"]) do |s|
s.name = data["name"]
subregion = Subregion.find_or_initialize_by(name: data["name"]) do |s|
s.region_id = data["region_id"]
end
puts "Sync Subregions[#{count}/#{sum}]: [#{subregion.name}]"