```ruby
class ZipCode < ApplicationRecord
  validates :name, presence: true
  validates :name, format: { with: /\A\d{5}(-\d{4})?\z/, message: 'is not a valid zip code' },
    if: 'name.present?'

  belongs_to :city
end
```

Make city a required property of zip code
user
```ruby
class ZipCode < ApplicationRecord
  validates :name, :city, presence: true
  validates :name, format: { with: /\A\d{5}(-\d{4})?\z/, message: 'is not a valid zip code' },
    if: 'name.present?'

  belongs_to :city
end
```
assistant