1 class OldRelation < ActiveRecord::Base
2 include ConsistencyValidations
4 set_table_name 'relations'
8 def self.from_relation(relation)
9 old_relation = OldRelation.new
10 old_relation.visible = relation.visible
11 old_relation.changeset_id = relation.changeset_id
12 old_relation.timestamp = relation.timestamp
13 old_relation.id = relation.id
14 old_relation.version = relation.version
15 old_relation.members = relation.members
16 old_relation.tags = relation.tags
20 def save_with_dependencies!
22 # see comment in old_way.rb ;-)
24 clear_aggregation_cache
25 clear_association_cache
26 @attributes.update(OldRelation.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
28 # ok, you can touch from here on
30 self.tags.each do |k,v|
31 tag = OldRelationTag.new
35 tag.version = self.version
40 self.members.each do |m|
41 member = OldRelationMember.new
43 member.member_type = m[0]
44 member.member_id = m[1]
45 member.member_role = m[2]
46 member.version = self.version
54 OldRelationMember.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |m|
55 @members += [[m.type,m.id,m.role]]
64 OldRelationTag.find(:all, :conditions => ["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.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
88 OldRelationTag.find(:all, :conditions => ['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 el1['user'] = self.changeset.user.display_name if self.changeset.user.data_public?
103 el1['version'] = self.version.to_s
104 el1['changeset'] = self.changeset_id.to_s
106 self.old_members.each do |member|
107 e = XML::Node.new 'member'
108 e['type'] = member.member_type.to_s
109 e['ref'] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
110 e['role'] = member.member_role.to_s
114 self.old_tags.each do |tag|
115 e = XML::Node.new 'tag'
123 # Temporary method to match interface to nodes
128 # Temporary method to match interface to relations
130 return self.old_members
133 # Pretend we're not in any relations
134 def containing_relation_members