+ ##
+ # updates the changeset bounding box to contain the bounding box of
+ # the element with given +type+ and +id+. this only works with nodes
+ # and ways at the moment, as they're the only elements to respond to
+ # the :bbox call.
+ def update_changeset_element(type, id)
+ element = Kernel.const_get(type.capitalize).find(id)
+ changeset.update_bbox! element.bbox
+ end
+
+ def delete_with_history!(new_relation, user)
+ if self.visible
+ 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
+ self.changeset_id = new_relation.changeset_id
+ self.tags = {}
+ self.members = []
+ self.visible = false
+ save_with_history!
+ else
+ raise OSM::APIAlreadyDeletedError.new
+ end
+ end
+
+ def update_from(new_relation, user)
+ check_consistency(self, new_relation, user)
+ if !new_relation.preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new
+ end
+ self.changeset_id = new_relation.changeset_id
+ self.tags = new_relation.tags
+ self.members = new_relation.members
+ 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
+