app/models/city.rb in geopolitical-0.9.3 vs app/models/city.rb in geopolitical-0.9.5

- old
+ new

@@ -4,26 +4,37 @@ class City include Mongoid::Document include Mongoid::Geospatial include Geopolitocracy - field :area, type: Integer # m2 square area - field :geom, type: Point, spatial: true + field :area, type: Integer # m2 square area + field :geom, type: Point, spatial: true + # field :capital, type: String spatial_scope :geom attr_writer :x, :y, :z belongs_to :region belongs_to :nation has_many :hoods + has_one :nation, as: :capital + has_one :region, as: :capital + before_validation :set_defaults, on: [:create] validates :name, uniqueness: { scope: :region_id } validate :region_inside_nation + scope :population, -> { order_by(souls: -1) } + + index nation_id: 1 + index souls: -1 + index name: 1, nation_id: 1 + index({ region_id: 1 }, sparse: true) + def region_inside_nation return if !region || region.nation == nation errors.add(:region, 'not inside Nation') end @@ -50,13 +61,15 @@ def postals hoods.map(&:postal) end def ==(other) + return unless other.is_a?(City) other && slug == other.slug end def <=>(other) + return unless other.is_a?(City) slug <=> other.slug end def with_region return name unless region