1 class OldWay < ActiveRecord::Base
2 include ConsistencyValidations
8 validates_associated :changeset
10 def self.from_way(way)
12 old_way.visible = way.visible
13 old_way.changeset_id = way.changeset_id
14 old_way.timestamp = way.timestamp
16 old_way.version = way.version
18 old_way.tags = way.tags
22 def save_with_dependencies!
24 # dont touch this unless you really have figured out why it's called
25 # (Rails doesn't deal well with the old ways table (called 'ways') because
26 # it doesn't have a unique key. It knows how to insert and auto_increment
27 # id and get it back but we have that and we want to get the 'version' back
28 # we could add another column but thats a lot of data. No, set_primary_key
29 # doesn't work either.
31 clear_aggregation_cache
32 clear_association_cache
33 @attributes.update(OldWay.find(:first, :conditions => ['id = ? AND timestamp = ?', self.id, self.timestamp]).instance_variable_get('@attributes'))
35 # ok, you can touch from here on
37 self.tags.each do |k,v|
42 tag.version = self.version
49 nd.id = [self.id, self.version, sequence]
59 OldWayNode.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version], :order => "sequence_id").each do |nd|
69 OldWayTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
73 @tags = Hash.new unless @tags
85 # has_many :way_nodes, :class_name => 'OldWayNode', :foreign_key => 'id'
86 # has_many :way_tags, :class_name => 'OldWayTag', :foreign_key => 'id'
89 OldWayNode.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
93 OldWayTag.find(:all, :conditions => ['id = ? AND version = ?', self.id, self.version])
97 el1 = XML::Node.new 'way'
98 el1['id'] = self.id.to_s
99 el1['visible'] = self.visible.to_s
100 el1['timestamp'] = self.timestamp.xmlschema
101 if self.changeset.user.data_public?
102 el1['user'] = self.changeset.user.display_name
103 el1['uid'] = self.changeset.user.id.to_s
105 el1['version'] = self.version.to_s
106 el1['changeset'] = self.changeset.id.to_s
108 self.old_nodes.each do |nd| # FIXME need to make sure they come back in the right order
109 e = XML::Node.new 'nd'
110 e['ref'] = nd.node_id.to_s
114 self.old_tags.each do |tag|
115 e = XML::Node.new 'tag'
123 # Read full version of old way
124 # For get_nodes_undelete, uses same nodes, even if they've moved since
125 # For get_nodes_revert, allocates new ids
126 # Currently returns Potlatch-style array
128 def get_nodes_undelete
132 points << [node.lon, node.lat, n, node.visible ? 1 : 0, node.tags_as_hash]
140 oldnode=OldNode.find(:first, :conditions=>['id=? AND timestamp<=?',n,self.timestamp], :order=>"timestamp DESC")
142 id=n; v=curnode.visible ? 1 : 0
143 if oldnode.lat!=curnode.lat or oldnode.lon!=curnode.lon or oldnode.tags!=curnode.tags then
144 # node has changed: if it's in other ways, give it a new id
145 if curnode.ways-[self.id] then id=-1; v=nil end
147 points << [oldnode.lon, oldnode.lat, id, v, oldnode.tags_as_hash]
152 # Temporary method to match interface to nodes
157 # Temporary method to match interface to ways
159 return self.old_nodes
162 # Pretend we're not in any relations
163 def containing_relation_members