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.version = way.version
14 old_way.tags = way.tags
18 def save_with_dependencies!
20 # dont touch this unless you really have figured out why it's called
21 # (Rails doesn't deal well with the old ways table (called 'ways') because
22 # it doesn't have a unique key. It knows how to insert and auto_increment
23 # id and get it back but we have that and we want to get the 'version' back
24 # we could add another column but thats a lot of data. No, set_primary_key
25 # doesn't work either.
27 clear_aggregation_cache
28 clear_association_cache
29 @attributes.update(OldWay.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
31 # ok, you can touch from here on
33 self.tags.each do |k,v|
38 tag.version = self.version
45 nd.id = [self.id, self.version, sequence]
55 OldWayNode.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version], :order => "sequence_id").each do |nd|
65 OldWayTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
69 @tags = Hash.new unless @tags
81 # has_many :way_nodes, :class_name => 'OldWayNode', :foreign_key => 'id'
82 # has_many :way_tags, :class_name => 'OldWayTag', :foreign_key => 'id'
85 OldWayNode.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
89 OldWayTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
93 el1 = XML::Node.new 'way'
94 el1['id'] = self.id.to_s
95 el1['visible'] = self.visible.to_s
96 el1['timestamp'] = self.timestamp.xmlschema
97 el1['user'] = self.user.display_name if self.user.data_public?
99 self.old_nodes.each do |nd| # FIXME need to make sure they come back in the right order
100 e = XML::Node.new 'nd'
101 e['ref'] = nd.node_id.to_s
105 self.old_tags.each do |tag|
106 e = XML::Node.new 'tag'