scope :ways, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids.flatten }) }
scope :relations, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids.flatten }) }
scope :ways, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids.flatten }) }
scope :relations, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids.flatten }) }
doc = p.parse
doc.find("//osm/relation").each do |pt|
return Relation.from_xml_node(pt, create)
end
doc = p.parse
doc.find("//osm/relation").each do |pt|
return Relation.from_xml_node(pt, create)
end
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("relation", xml, ex.message)
end
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("relation", xml, ex.message)
end
- fail OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt["version"].nil?
relation.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
relation.id = pt["id"].to_i
# .to_i will return 0 if there is no number that can be parsed.
# We want to make sure that there is no id with zero anyway
- fail OSM::APIBadXMLError.new("relation", pt, "tag is missing key") if tag["k"].nil?
- fail OSM::APIBadXMLError.new("relation", pt, "tag is missing value") if tag["v"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "tag is missing key") if tag["k"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "tag is missing value") if tag["v"].nil?
- fail OSM::APIBadXMLError.new("relation", pt, "The #{member['type']} is not allowed only, #{TYPES.inspect} allowed") unless TYPES.include? member["type"]
+ raise OSM::APIBadXMLError.new("relation", pt, "The #{member['type']} is not allowed only, #{TYPES.inspect} allowed") unless TYPES.include? member["type"]
# member_ref = member['ref']
# member_role
member["role"] ||= "" # Allow the upload to not include this, in which case we default to an empty string.
relation.add_member(member["type"].classify, member["ref"], member["role"])
end
# member_ref = member['ref']
# member_role
member["role"] ||= "" # Allow the upload to not include this, in which case we default to an empty string.
relation.add_member(member["type"].classify, member["ref"], member["role"])
end
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
end
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
# shouldn't be possible to get race conditions.
Relation.transaction do
end
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
# shouldn't be possible to get race conditions.
Relation.transaction do
check_consistency(self, new_relation, user)
# This will check to see if this relation is used by another relation
rel = RelationMember.joins(:relation).find_by("visible = ? AND member_type = 'Relation' and member_id = ? ", true, id)
check_consistency(self, new_relation, user)
# This will check to see if this relation is used by another relation
rel = RelationMember.joins(:relation).find_by("visible = ? AND member_type = 'Relation' and member_id = ? ", true, id)
check_consistency(self, new_relation, user)
unless new_relation.preconditions_ok?(members)
check_consistency(self, new_relation, user)
unless new_relation.preconditions_ok?(members)
def create_with_history(user)
check_create_consistency(self, user)
def create_with_history(user)
check_create_consistency(self, user)
- unless self.preconditions_ok?
- fail OSM::APIPreconditionFailedError.new("Cannot create relation: data or member data is invalid.")
+ unless preconditions_ok?
+ raise OSM::APIPreconditionFailedError.new("Cannot create relation: data or member data is invalid.")
# materially change the rest of the relation.
any_relations =
changed_members.collect { |_id, type| type == "relation" }
# materially change the rest of the relation.
any_relations =
changed_members.collect { |_id, type| type == "relation" }
update_members = if tags_changed || any_relations
# add all non-relation bounding boxes to the changeset
update_members = if tags_changed || any_relations
# add all non-relation bounding boxes to the changeset