1 class OldWay < ActiveRecord::Base
8 old_way.user_id = way.user_id
9 old_way.timestamp = way.timestamp
11 old_way.segs = way.segs
12 old_way.tags = way.tags
16 def save_with_dependencies
18 # dont touch this unless you really have figured out why it's called
19 # (Rails doesn't deal well with the old ways table (called 'ways') because
20 # it doesn't have a unique key. It knows how to insert and auto_increment
21 # id and get it back but we have that and we want to get the 'version' back
22 # we could add another column but thats a lot of data. No, set_primary_key
23 # doesn't work either.
25 clear_aggregation_cache
26 clear_association_cache
27 @attributes.update(OldWay.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
29 # ok, you can touch from here on
31 self.tags.each do |k,v|
36 tag.version = self.version
42 seg = OldWaySegment.new
45 seg.version = self.version
51 @segs = Array.new unless @segs
56 @tags = Hash.new unless @tags
68 # has_many :way_segments, :class_name => 'OldWaySegment', :foreign_key => 'id'
69 # has_many :way_tags, :class_name => 'OldWayTag', :foreign_key => 'id'
72 OldWaySegment.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
76 OldWayTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
80 el1 = XML::Node.new 'way'
81 el1['id'] = self.id.to_s
82 el1['visible'] = self.visible.to_s
83 el1['timestamp'] = self.timestamp.xmlschema
85 self.old_segments.each do |seg| # FIXME need to make sure they come back in the right order
86 e = XML::Node.new 'seg'
87 e['id'] = seg.segment_id.to_s
91 self.old_tags.each do |tag|
92 e = XML::Node.new 'tag'