# first collect nodes, ways, and relations referenced by this relation.
ways = Way.find_by_sql("select w.* from current_ways w,current_relation_members rm where "+
- "rm.member_type='way' and rm.member_id=w.id and rm.id=#{relation.id}");
+ "rm.member_type='Way' and rm.member_id=w.id and rm.id=#{relation.id}");
nodes = Node.find_by_sql("select n.* from current_nodes n,current_relation_members rm where "+
- "rm.member_type='node' and rm.member_id=n.id and rm.id=#{relation.id}");
+ "rm.member_type='Node' and rm.member_id=n.id and rm.id=#{relation.id}");
# note query is built to exclude self just in case.
relations = Relation.find_by_sql("select r.* from current_relations r,current_relation_members rm where "+
- "rm.member_type='relation' and rm.member_id=r.id and rm.id=#{relation.id} and r.id<>rm.id");
+ "rm.member_type='Relation' and rm.member_id=r.id and rm.id=#{relation.id} and r.id<>rm.id");
# now additionally collect nodes referenced by ways. Note how we recursively
# evaluate ways but NOT relations.
end
def relations_for_way
- relations_for_object("way")
+ relations_for_object("Way")
end
def relations_for_node
- relations_for_object("node")
+ relations_for_object("Node")
end
def relations_for_relation
- relations_for_object("relation")
+ relations_for_object("Relation")
end
def relations_for_object(objtype)
check_consistency(self, new_node, user)
if WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", :conditions => [ "current_ways.visible = ? AND current_way_nodes.node_id = ?", true, self.id ])
raise OSM::APIPreconditionFailedError.new
- elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='node' and member_id=? ", true, self.id])
+ elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = ? AND member_type='Node' and member_id=? ", true, self.id])
raise OSM::APIPreconditionFailedError.new
else
self.changeset_id = new_node.changeset_id
self.members.each_with_index do |m,i|
member = OldRelationMember.new
member.id = [self.id, self.version, i]
- member.member_type = m[0]
+ member.member_type = m[0].classify
member.member_id = m[1]
member.member_role = m[2]
member.save!
self.old_members.each do |member|
e = XML::Node.new 'member'
- e['type'] = member.member_type.to_s
+ e['type'] = member.member_type.to_s.downcase
e['ref'] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
e['role'] = member.member_role.to_s
el1 << e
#member_role
member['role'] ||= "" # Allow the upload to not include this, in which case we default to an empty string.
logger.debug member['role']
- relation.add_member(member['type'], member['ref'], member['role'])
+ relation.add_member(member['type'].classify, member['ref'], member['role'])
end
raise OSM::APIBadUserInput.new("Some bad xml in relation") if relation.nil?
#end
if p
e = XML::Node.new 'member'
- e['type'] = member.member_type
+ e['type'] = member.member_type.downcase
e['ref'] = member.member_id.to_s
e['role'] = member.member_role
el1 << e
if ids.empty?
return []
else
- self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'node' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
+ self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'Node' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
return self.find(:all, options)
end
end
if ids.empty?
return []
else
- self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'way' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
+ self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'Way' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
return self.find(:all, options)
end
end
if ids.empty?
return []
else
- self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'relation' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
+ self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'Relation' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
return self.find(:all, options)
end
end
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 ])
+ 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
elements = { :node => Hash.new, :way => Hash.new, :relation => Hash.new }
self.members.each do |m|
# find the hash for the element type or die
- hash = elements[m[0].to_sym] or return false
-
+ 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]
# use reflection to look up the appropriate class
model = Kernel.const_get(m[0].capitalize)
-
# get the element with that ID
element = model.find(m[1])
self.members.map! do |type, id, role|
old_id = id.to_i
if old_id < 0
- new_id = id_map[type.to_sym][old_id]
+ new_id = id_map[type.downcase.to_sym][old_id]
raise "invalid placeholder" if new_id.nil?
[type, new_id, role]
else
# FIXME: check for tag changes along with element deletions and
# make sure that the deleted element's bounding box is hit.
self.members.each do |type, id, role|
- if type != "relation"
+ if type != "Relation"
update_changeset_element(type, id)
end
end
else
# add only changed members to the changeset
changed_members.each do |id, type|
- update_changeset_element(type, id)
+ if type != "Relation"
+ update_changeset_element(type, id)
+ end
end
end
belongs_to :relation, :foreign_key => :id
def after_find
- self[:member_class] = self.member_type.capitalize
+ self[:member_class] = self.member_type.classify
end
def after_initialize
- self[:member_class] = self.member_type.capitalize unless self.member_type.nil?
+ self[:member_class] = self.member_type.classify unless self.member_type.nil?
end
def before_save
- self.member_type = self[:member_class].downcase
+ self.member_type = self[:member_class].classify
end
def member_type=(type)
Way.transaction do
check_consistency(self, new_way, user)
if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id",
- :conditions => [ "visible = ? AND member_type='way' and member_id=? ", true, self.id])
+ :conditions => [ "visible = ? AND member_type='Way' and member_id=? ", true, self.id])
raise OSM::APIPreconditionFailedError.new("You need to make sure that this way is not a member of a relation.")
else
self.changeset_id = new_way.changeset_id
end
def alter_column_nwr_enum (table_name, column)
- execute "alter table #{table_name} change column #{column} #{column} enum('node','way','relation');"
+ execute "alter table #{table_name} change column #{column} #{column} enum('Node','Way','Relation');"
end
def alter_primary_key(table_name, new_columns)
def alter_column_nwr_enum (table_name, column)
response = select_one("select count(*) as count from pg_type where typname = 'nwr_enum'")
if response['count'] == "0" #yep, as a string
- execute "create type nwr_enum as ENUM ('node', 'way', 'relation')"
+ execute "create type nwr_enum as ENUM ('Node', 'Way', 'Relation')"
end
execute "alter table #{table_name} drop #{column}"
execute "alter table #{table_name} add #{column} nwr_enum"
t1:
id: 1
member_role: "some"
- member_type: "way"
+ member_type: "Way"
member_id: 3
t2:
id: 1
member_role: "some"
- member_type: "node"
+ member_type: "Node"
member_id: 5
t3:
id: 1
member_role: "some"
- member_type: "relation"
+ member_type: "Relation"
member_id: 3
t4:
id: 3
member_role: "some"
- member_type: "node"
+ member_type: "Node"
member_id: 5
t5:
id: 2
member_role: "some"
- member_type: "node"
+ member_type: "Node"
member_id: 5
t1:
id: 1
member_role: "some"
- member_type: "way"
+ member_type: "Way"
member_id: 3
version: 1
t2:
id: 1
member_role: "some"
- member_type: "node"
+ member_type: "Node"
member_id: 5
version: 1
t3:
id: 1
member_role: "some"
- member_type: "relation"
+ member_type: "Relation"
member_id: 3
version: 1
t4:
id: 3
member_role: "some"
- member_type: "node"
+ member_type: "Node"
member_id: 5
version: 1