From d0e16cdb6caa102f15894811d26c506f18a830a6 Mon Sep 17 00:00:00 2001 From: Shaun McDonald Date: Tue, 5 May 2009 17:07:06 +0000 Subject: [PATCH] be a bit more specific when a way is a member of a relation. Actually return an error message when a relation precondition fails. Remove a debug statement. --- app/models/relation.rb | 2 +- app/models/way.rb | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/models/relation.rb b/app/models/relation.rb index 09143294c..787c16719 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -288,7 +288,6 @@ class Relation < ActiveRecord::Base elements = { :node => Hash.new, :way => Hash.new, :relation => Hash.new } self.members.each do |m| # find the hash for the element type or die - logger.debug m[0] hash = elements[m[0].downcase.to_sym] or return false # unless its in the cache already unless hash.key? m[1] @@ -299,6 +298,7 @@ class Relation < ActiveRecord::Base # and check that it is OK to use. unless element and element.visible? and element.preconditions_ok? + raise OSM::APIPreconditionFailedError.new("Relation with id #{self.id} cannot be saved due to #{m[0]} with id #{element.id}") return false end hash[m[1]] = true diff --git a/app/models/way.rb b/app/models/way.rb index 64b399133..1480361e0 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -251,18 +251,17 @@ class Way < ActiveRecord::Base # shouldn't be possible to get race conditions. Way.transaction do check_consistency(self, new_way, user) - if RelationMember.find(:first, :joins => :relation, + rel = RelationMember.find(:first, :joins => :relation, :conditions => [ "visible = ? AND member_type='Way' and member_id=? ", true, self.id]) - raise OSM::APIPreconditionFailedError.new("You need to make sure that the way with id: #{self.id} is not a member of a relation.") - else - self.changeset_id = new_way.changeset_id - self.changeset = new_way.changeset - - self.tags = [] - self.nds = [] - self.visible = false - save_with_history! - end + raise OSM::APIPreconditionFailedError.new("You need to make sure that the way with id: #{self.id} is not a member of the relation with id #{rel.id}.") if rel + + self.changeset_id = new_way.changeset_id + self.changeset = new_way.changeset + + self.tags = [] + self.nds = [] + self.visible = false + save_with_history! end end -- 2.43.2