lib/sportdb/models/city.rb in sportdb-0.5.3 vs lib/sportdb/models/city.rb in sportdb-0.5.4

- old
+ new

@@ -2,19 +2,18 @@ class City < ActiveRecord::Base self.table_name = 'cities' belongs_to :country, :class_name => 'Country', :foreign_key => 'country_id' + belongs_to :region, :class_name => 'Region', :foreign_key => 'country_id' has_many :teams, :class_name => 'Team', :foreign_key => 'city_id' def self.create_from_ary!( cities, more_values={} ) cities.each do |values| - ## todo/fix: split optional synonyms from title (see team for example) - ## key & title & country required attr = { key: values[0] } @@ -30,9 +29,13 @@ ## check for optional values values[2..-1].each do |value| if value.is_a? Country attr[ :country_id ] = value.id + elsif value =~ /^region:/ ## region: + value_region_key = value[7..-1] ## cut off region: prefix + value_region = Region.find_by_key!( value_region_key ) + attr[ :region_id ] = value_region.id else # issue warning: unknown type for value end end \ No newline at end of file