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.changeset.user.display_name if self.changeset.user.data_public?
100 el1['version'] = self.version.to_s
101 el1['changeset'] = self.changeset.id.to_s
103 self.old_nodes.each do |nd| # FIXME need to make sure they come back in the right order
104 e = XML::Node.new 'nd'
105 e['ref'] = nd.node_id.to_s
109 self.old_tags.each do |tag|
110 e = XML::Node.new 'tag'
118 # Read full version of old way
119 # For get_nodes_undelete, uses same nodes, even if they've moved since
120 # For get_nodes_revert, allocates new ids
121 # Currently returns Potlatch-style array
123 def get_nodes_undelete
127 points << [node.lon, node.lat, n, node.visible ? 1 : 0, node.tags_as_hash]
135 oldnode=OldNode.find(:first, :conditions=>['id=? AND timestamp<=?',n,self.timestamp], :order=>"timestamp DESC")
137 id=n; v=curnode.visible ? 1 : 0
138 if oldnode.lat!=curnode.lat or oldnode.lon!=curnode.lon or oldnode.tags!=curnode.tags then
139 # node has changed: if it's in other ways, give it a new id
140 if curnode.ways-[self.id] then id=-1; v=nil end
142 points << [oldnode.lon, oldnode.lat, id, v, oldnode.tags_as_hash]
147 # Temporary method to match interface to nodes
152 # Temporary method to match interface to ways
154 return self.old_nodes
157 # Pretend we're not in any relations
158 def containing_relation_members