]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
Creating consistency check for creation of nodes, way and relations. Moving some...
[rails.git] / app / models / relation.rb
index c8ee89d374aa63a69a282dd1d2806c0ea1ee1090..195090e4b1f2755593773bc1fafb4755c0f37e6d 100644 (file)
@@ -1,6 +1,8 @@
 class Relation < ActiveRecord::Base
   require 'xml/libxml'
   
+  include ConsistencyValidations
+  
   set_table_name 'current_relations'
 
   belongs_to :changeset
@@ -75,7 +77,7 @@ class Relation < ActiveRecord::Base
     
     if user_display_name_cache and user_display_name_cache.key?(self.changeset.user_id)
       # use the cache if available
-    elsif self.user.data_public?
+    elsif self.changeset.user.data_public?
       user_display_name_cache[self.changeset.user_id] = self.changeset.user.display_name
     else
       user_display_name_cache[self.changeset.user_id] = nil
@@ -249,6 +251,16 @@ class Relation < ActiveRecord::Base
     self.visible = true
     save_with_history!
   end
+  
+  def create_with_history(user)
+    check_create_consistency(self, user)
+    if !self.preconditions_ok?
+      raise OSM::APIPreconditionFailedError.new
+    end
+    self.version = 0
+    self.visible = true
+    save_with_history!
+  end
 
   def preconditions_ok?
     # These are hastables that store an id in the index of all