From 34342a9678ee03bca353b41262f46e4b1b16fb3c Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 12 Feb 2025 13:08:12 +0800 Subject: [PATCH] refactor: make country and state associations optional - Change 'belongs_to :country' association to be optional - Change 'belongs_to :state' association to be optional This refactoring allows a City record to exist without having an associated Country or State, thus increasing the flexibility of the data model for various use cases. --- app/models/city.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/city.rb b/app/models/city.rb index 87b730c..153bf92 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -1,7 +1,7 @@ class City < ApplicationRecord extend FriendlyId friendly_id :slug_candidates, use: :slugged - belongs_to :country + belongs_to :country, optional: true belongs_to :state, optional: true has_many :weather_arts, dependent: :destroy