1 class OldWay < ActiveRecord::Base
2 include ConsistencyValidations
10 old_way.visible = way.visible
11 old_way.changeset_id = way.changeset_id
12 old_way.timestamp = way.timestamp
14 old_way.version = way.version
16 old_way.tags = way.tags
20 def save_with_dependencies!
22 # dont touch this unless you really have figured out why it's called
23 # (Rails doesn't deal well with the old ways table (called 'ways') because
24 # it doesn't have a unique key. It knows how to insert and auto_increment
25 # id and get it back but we have that and we want to get the 'version' back
26 # we could add another column but thats a lot of data. No, set_primary_key
27 # doesn't work either.
29 clear_aggregation_cache
30 clear_association_cache
31 @attributes.update(OldWay.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
33 # ok, you can touch from here on
35 self.tags.each do |k,v|
40 tag.version = self.version
47 nd.id = [self.id, self.version, sequence]
57 OldWayNode.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version], :order => "sequence_id").each do |nd|
67 OldWayTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
71 @tags = Hash.new unless @tags
83 # has_many :way_nodes, :class_name => 'OldWayNode', :foreign_key => 'id'
84 # has_many :way_tags, :class_name => 'OldWayTag', :foreign_key => 'id'
87 OldWayNode.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
91 OldWayTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
95 el1 = XML::Node.new 'way'
96 el1['id'] = self.id.to_s
97 el1['visible'] = self.visible.to_s
98 el1['timestamp'] = self.timestamp.xmlschema
99 el1['user'] = self.user.display_name if self.user.data_public?
100 el1['version'] = self.version.to_s
102 self.old_nodes.each do |nd| # FIXME need to make sure they come back in the right order
103 e = XML::Node.new 'nd'
104 e['ref'] = nd.node_id.to_s
108 self.old_tags.each do |tag|
109 e = XML::Node.new 'tag'
117 # Read full version of old way
118 # For get_nodes_undelete, uses same nodes, even if they've moved since
119 # For get_nodes_revert, allocates new ids
120 # Currently returns Potlatch-style array
122 def get_nodes_undelete
126 points << [node.lon, node.lat, n, node.visible ? 1 : 0, node.tags_as_hash]
134 oldnode=OldNode.find(:first, :conditions=>['id=? AND timestamp<=?',n,self.timestamp], :order=>"timestamp DESC")
136 id=n; v=curnode.visible ? 1 : 0
137 if oldnode.lat!=curnode.lat or oldnode.lon!=curnode.lon or oldnode.tags!=curnode.tags then
138 # node has changed: if it's in other ways, give it a new id
139 if curnode.ways-[self.id] then id=-1; v=nil end
141 points << [oldnode.lon, oldnode.lat, id, v, oldnode.tags_as_hash]
146 # Temporary method to match interface to nodes
151 # Temporary method to match interface to ways
153 return self.old_nodes
156 # Pretend we're not in any relations
157 def containing_relation_members