1 class OldRelation < ActiveRecord::Base
2 include ConsistencyValidations
4 self.table_name = "relations"
5 self.primary_keys = "relation_id", "version"
9 has_many :old_members, :class_name => 'OldRelationMember', :foreign_key => [:relation_id, :version], :order => :sequence_id
10 has_many :old_tags, :class_name => 'OldRelationTag', :foreign_key => [:relation_id, :version]
12 validates_associated :changeset
14 def self.from_relation(relation)
15 old_relation = OldRelation.new
16 old_relation.visible = relation.visible
17 old_relation.changeset_id = relation.changeset_id
18 old_relation.timestamp = relation.timestamp
19 old_relation.relation_id = relation.id
20 old_relation.version = relation.version
21 old_relation.members = relation.members
22 old_relation.tags = relation.tags
26 def save_with_dependencies!
28 # see comment in old_way.rb ;-)
30 clear_aggregation_cache
31 clear_association_cache
32 @attributes.update(OldRelation.where(:relation_id => self.relation_id, :timestamp => self.timestamp).order("version DESC").first.instance_variable_get('@attributes'))
34 # ok, you can touch from here on
36 self.tags.each do |k,v|
37 tag = OldRelationTag.new
40 tag.relation_id = self.relation_id
41 tag.version = self.version
45 self.members.each_with_index do |m,i|
46 member = OldRelationMember.new
47 member.id = [self.relation_id, self.version, i]
48 member.member_type = m[0].classify
49 member.member_id = m[1]
50 member.member_role = m[2]
58 OldRelationMember.where(:relation_id => self.relation_id, :version => self.version).order(:sequence_id).each do |m|
59 @members += [[m.type,m.id,m.role]]
68 OldRelationTag.where(:relation_id => self.relation_id, :version => self.version).each do |tag|
72 @tags = Hash.new unless @tags
85 doc = OSM::API.new.get_xml_doc
86 doc.root << to_xml_node()
91 el1 = XML::Node.new 'relation'
92 el1['id'] = self.relation_id.to_s
93 el1['visible'] = self.visible.to_s
94 el1['timestamp'] = self.timestamp.xmlschema
95 if self.changeset.user.data_public?
96 el1['user'] = self.changeset.user.display_name
97 el1['uid'] = self.changeset.user.id.to_s
99 el1['version'] = self.version.to_s
100 el1['changeset'] = self.changeset_id.to_s
102 self.old_members.each do |member|
103 e = XML::Node.new 'member'
104 e['type'] = member.member_type.to_s.downcase
105 e['ref'] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
106 e['role'] = member.member_role.to_s
110 self.old_tags.each do |tag|
111 e = XML::Node.new 'tag'
119 # Temporary method to match interface to nodes
124 # Temporary method to match interface to relations
126 return self.old_members
129 # Pretend we're not in any relations
130 def containing_relation_members