]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/way.rb
Fixed precondition typo and segment_controller foreign key
[rails.git] / app / models / way.rb
index 0c53e5e87c08ce090b7a05561a001ea54c9705c6..55a578acdbbd5d42a32476618b76bbd453039b33 100644 (file)
@@ -6,6 +6,8 @@ class Way < ActiveRecord::Base
   has_many :way_segments, :foreign_key => 'id'
   has_many :way_tags, :foreign_key => 'id'
 
+  has_many :old_ways, :foreign_key => :id
+
   set_table_name 'current_ways'
 
   def self.from_xml(xml, create=false)
@@ -16,7 +18,7 @@ class Way < ActiveRecord::Base
     way = Way.new
 
     doc.find('//osm/way').each do |pt|
-      unless create and pt['id'] == '0'
+      if !create and pt['id'] != '0'
         way.id = pt['id'].to_i
       end
 
@@ -137,4 +139,14 @@ class Way < ActiveRecord::Base
     old_way.save_with_dependencies
   end
 
+  def preconditions_ok?
+    self.segs.each do |n|
+      segment = Segment.find(n)
+      unless segment and segment.visible and segment.preconditions_ok?
+        return false
+      end
+    end
+    return true
+  end
+
 end