1 class OldWay < ActiveRecord::Base
8 old_way.visible = way.visible
9 old_way.user_id = way.user_id
10 old_way.timestamp = way.timestamp
12 old_way.segs = way.segs
13 old_way.tags = way.tags
17 def save_with_dependencies!
19 # dont touch this unless you really have figured out why it's called
20 # (Rails doesn't deal well with the old ways table (called 'ways') because
21 # it doesn't have a unique key. It knows how to insert and auto_increment
22 # id and get it back but we have that and we want to get the 'version' back
23 # we could add another column but thats a lot of data. No, set_primary_key
24 # doesn't work either.
26 clear_aggregation_cache
27 clear_association_cache
28 @attributes.update(OldWay.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
30 # ok, you can touch from here on
32 self.tags.each do |k,v|
37 tag.version = self.version
43 seg = OldWaySegment.new
46 seg.version = self.version
52 @segs = Array.new unless @segs
57 @tags = Hash.new unless @tags
69 # has_many :way_segments, :class_name => 'OldWaySegment', :foreign_key => 'id'
70 # has_many :way_tags, :class_name => 'OldWayTag', :foreign_key => 'id'
73 OldWaySegment.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
77 OldWayTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
81 el1 = XML::Node.new 'way'
82 el1['id'] = self.id.to_s
83 el1['visible'] = self.visible.to_s
84 el1['timestamp'] = self.timestamp.xmlschema
85 el1['user'] = self.user.display_name if self.user.data_public?
87 self.old_segments.each do |seg| # FIXME need to make sure they come back in the right order
88 e = XML::Node.new 'seg'
89 e['id'] = seg.segment_id.to_s
93 self.old_tags.each do |tag|
94 e = XML::Node.new 'tag'