1 class OldRelation < ActiveRecord::Base
2 set_table_name 'relations'
6 def self.from_relation(relation)
7 old_relation = OldRelation.new
8 old_relation.visible = relation.visible
9 old_relation.user_id = relation.user_id
10 old_relation.timestamp = relation.timestamp
11 old_relation.id = relation.id
12 old_relation.version = relation.version
13 old_relation.members = relation.members
14 old_relation.tags = relation.tags
18 def save_with_dependencies!
20 # see comment in old_way.rb ;-)
22 clear_aggregation_cache
23 clear_association_cache
24 @attributes.update(OldRelation.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
26 # ok, you can touch from here on
28 self.tags.each do |k,v|
29 tag = OldRelationTag.new
33 tag.version = self.version
38 self.members.each do |m|
39 member = OldRelationMember.new
41 member.member_type = m[0]
42 member.member_id = m[1]
43 member.member_role = m[2]
44 member.version = self.version
52 OldRelationMember.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |m|
53 @members += [[m.type,m.id,m.role]]
62 OldRelationTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
66 @tags = Hash.new unless @tags
78 # has_many :relation_segments, :class_name => 'OldRelationSegment', :foreign_key => 'id'
79 # has_many :relation_tags, :class_name => 'OldRelationTag', :foreign_key => 'id'
82 OldRelationMember.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
86 OldRelationTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
90 el1 = XML::Node.new 'relation'
91 el1['id'] = self.id.to_s
92 el1['visible'] = self.visible.to_s
93 el1['timestamp'] = self.timestamp.xmlschema
94 el1['user'] = self.user.display_name if self.user.data_public?
95 el1['version'] = self.version.to_s
97 self.old_members.each do |member|
98 e = XML::Node.new 'member'
99 e['type'] = member.member_type.to_s
100 e['ref'] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
101 e['role'] = member.member_role.to_s
105 self.old_tags.each do |tag|
106 e = XML::Node.new 'tag'