Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Rails models for geographic domain data
class City < ActiveRecord::Base
self.primary_keys = :country_name, :subregion_name, :name
belongs_to :subregion, foreign_key: [:country_name, :subregion_name]
default_scope { order('name') }
end
class Country < ActiveRecord::Base
self.primary_key = :name
has_many :subregions, foreign_key: :country_name
default_scope { order('name') }
end
class Subregion < ActiveRecord::Base
self.primary_keys = :country_name, :name
has_many :cities, foreign_key: [:country_name, :subregion_name]
belongs_to :country, foreign_key: :country_name
default_scope { order('name') }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment