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.members = relation.members
13 old_relation.tags = relation.tags
17 def save_with_dependencies!
19 # see comment in old_way.rb ;-)
21 clear_aggregation_cache
22 clear_association_cache
23 @attributes.update(OldRelation.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
25 # ok, you can touch from here on
27 self.tags.each do |k,v|
28 tag = OldRelationTag.new
32 tag.version = self.version
37 self.members.each do |m|
38 member = OldRelationMember.new
40 member.member_type = m[0]
41 member.member_id = m[1]
42 member.member_role = m[2]
43 member.version = self.version
51 OldRelationMember.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |m|
52 @members += [[m.type,m.id,m.role]]
61 OldRelationTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
65 @tags = Hash.new unless @tags
77 # has_many :relation_segments, :class_name => 'OldRelationSegment', :foreign_key => 'id'
78 # has_many :relation_tags, :class_name => 'OldRelationTag', :foreign_key => 'id'
81 OldRelationMember.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
85 OldRelationTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
89 el1 = XML::Node.new 'relation'
90 el1['id'] = self.id.to_s
91 el1['visible'] = self.visible.to_s
92 el1['timestamp'] = self.timestamp.xmlschema
93 el1['user'] = self.user.display_name if self.user.data_public?
95 self.old_members.each do |member|
96 e = XML::Node.new 'member'
97 e['type'] = member.member_type.to_s
98 e['ref'] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML
99 e['role'] = member.member_role.to_s
103 self.old_tags.each do |tag|
104 e = XML::Node.new 'tag'