Created
February 4, 2014 19:11
-
-
Save bluerogue251/8810260 to your computer and use it in GitHub Desktop.
Rails models for geographic domain data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Country < ActiveRecord::Base | |
self.primary_key = :name | |
has_many :subregions, foreign_key: :country_name | |
default_scope { order('name') } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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