+
+ # delete a way and its nodes that aren't part of other ways, with history
+
+ # FIXME: merge the potlatch code to delete the relations
+ # and refactor to use delete_with_history!
+ def delete_with_relations_and_nodes_and_history(changeset_id)
+ # delete the nodes not used by other ways
+ self.unshared_node_ids.each do |node_id|
+ n = Node.find(node_id)
+ n.changeset_id = changeset_id
+ n.visible = false
+ n.save_with_history!
+ end
+
+ self.changeset_id = changeset_id
+ self.tags = []
+ self.nds = []
+ self.visible = false
+ self.save_with_history!
+ end
+
+ # Find nodes that belong to this way only
+ def unshared_node_ids
+ node_ids = self.nodes.collect { |node| node.id }
+
+ unless node_ids.empty?
+ way_nodes = WayNode.find(:all, :conditions => "node_id in (#{node_ids.join(',')}) and id != #{self.id}")
+ node_ids = node_ids - way_nodes.collect { |way_node| way_node.node_id }
+ end
+
+ return node_ids
+ end
+
+ # Temporary method to match interface to nodes
+ def tags_as_hash
+ return self.tags
+ end
+
+ ##
+ # if any referenced nodes are placeholder IDs (i.e: are negative) then
+ # this calling this method will fix them using the map from placeholders
+ # to IDs +id_map+.
+ def fix_placeholders!(id_map)
+ self.nds.map! do |node_id|
+ if node_id < 0
+ new_id = id_map[:node][node_id]
+ raise "invalid placeholder for #{node_id.inspect}: #{new_id.inspect}" if new_id.nil?
+ new_id
+ else
+ node_id
+ end
+ end
+ end
+