1 class OldRelation < ActiveRecord::Base
2 include ConsistencyValidations
4 set_table_name 'relations'
8 validates_associated :changeset
10 def self.from_relation(relation)
11 old_relation = OldRelation.new
12 old_relation.visible = relation.visible
13 old_relation.changeset_id = relation.changeset_id
14 old_relation.timestamp = relation.timestamp
15 old_relation.id = relation.id
16 old_relation.version = relation.version
17 old_relation.members = relation.members
18 old_relation.tags = relation.tags
22 def save_with_dependencies!
24 # see comment in old_way.rb ;-)
26 clear_aggregation_cache
27 clear_association_cache
28 @attributes.update(OldRelation.where('id = ? AND timestamp = ?', self.id, self.timestamp).order("version DESC").first.instance_variable_get('@attributes'))
30 # ok, you can touch from here on
32 self.tags.each do |k,v|
33 tag = OldRelationTag.new
37 tag.version = self.version
41 self.members.each_with_index do |m,i|
42 member = OldRelationMember.new
43 member.id = [self.id, self.version, i]
44 member.member_type = m[0].classify
45 member.member_id = m[1]
46 member.member_role = m[2]
54 OldRelationMember.where("id = ? AND version = ?", self.id, self.version).order(:sequence_id).each do |m|
55 @members += [[m.type,m.id,m.role]]
64 OldRelationTag.where("id = ? AND version = ?", self.id, self.version).each do |tag|
68 @tags = Hash.new unless @tags
80 # has_many :relation_segments, :class_name => 'OldRelationSegment', :foreign_key => 'id'
81 # has_many :relation_tags, :class_name => 'OldRelationTag', :foreign_key => 'id'
84 OldRelationMember.where('id = ? AND version = ?', self.id, self.version).order(:sequence_id)
88 OldRelationTag.where('id = ? AND version = ?', self.id, self.version)
92 doc = OSM::API.new.get_xml_doc
93 doc.root << to_xml_node()
98 el1 = XML::Node.new 'relation'
99 el1['id'] = self.id.to_s
100 el1['visible'] = self.visible.to_s
101 el1['timestamp'] = self.timestamp.xmlschema
102 if self.changeset.user.data_public?
103 el1['user'] = self.changeset.user.display_name
104 el1['uid'] = self.changeset.user.id.to_s
106 el1['version'] = self.version.to_s
107 el1['changeset'] = self.changeset_id.to_s
109 self.old_members.each do |member|
110 e = XML::Node.new 'member'
111 e['type'] = member.member_type.to_s.downcase
112 e['ref'] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
113 e['role'] = member.member_role.to_s
117 self.old_tags.each do |tag|
118 e = XML::Node.new 'tag'
126 # Temporary method to match interface to nodes
131 # Temporary method to match interface to relations
133 return self.old_members
136 # Pretend we're not in any relations
137 def containing_relation_members