]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
Remove debugging statement.
[rails.git] / app / models / relation.rb
index 36d6943d97106e9ecfd42242fc8575c1932839e2..f9bba98539b719fb69dc1c88a0be362d8d88516e 100644 (file)
@@ -227,7 +227,7 @@ class Relation < ActiveRecord::Base
 
   def delete_with_history!(new_relation, user)
     unless self.visible
-      raise OSM::APIAlreadyDeletedError.new
+      raise OSM::APIAlreadyDeletedError.new("relation", new_relation.id)
     end
 
     # need to start the transaction here, so that the database can 
@@ -236,9 +236,9 @@ class Relation < ActiveRecord::Base
     Relation.transaction do
       check_consistency(self, new_relation, user)
       # This will check to see if this relation is used by another relation
-      if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Relation' and member_id=? ", true, self.id ])
-        raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is a used in another relation")
-      end
+      rel = RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Relation' and member_id=? ", true, self.id ])
+      raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is a used in relation #{rel.id}.") unless rel.nil?
+
       self.changeset_id = new_relation.changeset_id
       self.tags = {}
       self.members = []
@@ -249,8 +249,8 @@ class Relation < ActiveRecord::Base
 
   def update_from(new_relation, user)
     check_consistency(self, new_relation, user)
-    if !new_relation.preconditions_ok?
-      raise OSM::APIPreconditionFailedError.new
+    unless new_relation.preconditions_ok?
+      raise OSM::APIPreconditionFailedError.new("Cannot update relation #{self.id}: data or member data is invalid.")
     end
     self.changeset_id = new_relation.changeset_id
     self.changeset = new_relation.changeset
@@ -262,8 +262,8 @@ class Relation < ActiveRecord::Base
   
   def create_with_history(user)
     check_create_consistency(self, user)
-    if !self.preconditions_ok?
-      raise OSM::APIPreconditionFailedError.new
+    unless self.preconditions_ok?
+      raise OSM::APIPreconditionFailedError.new("Cannot create relation: data or member data is invalid.")
     end
     self.version = 0
     self.visible = true
@@ -338,7 +338,7 @@ class Relation < ActiveRecord::Base
       self.timestamp = t
       self.save!
 
-      tags = self.tags
+      tags = self.tags.clone
       self.relation_tags.each do |old_tag|
         key = old_tag.k
         # if we can match the tags we currently have to the list
@@ -346,11 +346,7 @@ class Relation < ActiveRecord::Base
         # if any are different then set the flag and do the DB 
         # update.
         if tags.has_key? key 
-          # rails 2.1 dirty handling should take care of making this
-          # somewhat efficient... hopefully...
-          old_tag.v = tags[key]
-          tags_changed |= old_tag.changed?
-          old_tag.save!
+          tags_changed |= (old_tag.v != tags[key])
 
           # remove from the map, so that we can expect an empty map
           # at the end if there are no new tags
@@ -359,13 +355,13 @@ class Relation < ActiveRecord::Base
         else
           # this means a tag was deleted
           tags_changed = true
-          RelationTag.delete_all ['id = ? and k = ?', self.id, old_tag.k]
         end
       end
       # if there are left-over tags then they are new and will have to
       # be added.
       tags_changed |= (not tags.empty?)
-      tags.each do |k,v|
+      RelationTag.delete_all(:id => self.id)
+      self.tags.each do |k,v|
         tag = RelationTag.new
         tag.k = k
         tag.v = v
@@ -373,10 +369,6 @@ class Relation < ActiveRecord::Base
         tag.save!
       end
       
-      # reload, so that all of the members are accessible in their
-      # new state.
-      self.reload
-
       # same pattern as before, but this time we're collecting the
       # changed members in an array, as the bounding box updates for
       # elements are per-element, not blanked on/off like for tags.