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.
This commit is contained in:
songtianlun 2025-02-12 13:08:12 +08:00
parent 8fce45e1d0
commit 34342a9678

View File

@ -1,7 +1,7 @@
class City < ApplicationRecord class City < ApplicationRecord
extend FriendlyId extend FriendlyId
friendly_id :slug_candidates, use: :slugged friendly_id :slug_candidates, use: :slugged
belongs_to :country belongs_to :country, optional: true
belongs_to :state, optional: true belongs_to :state, optional: true
has_many :weather_arts, dependent: :destroy has_many :weather_arts, dependent: :destroy