1 class OldNode < ActiveRecord::Base
3 include ConsistencyValidations
7 validates_presence_of :changeset_id, :timestamp
8 validates_inclusion_of :visible, :in => [ true, false ]
9 validates_numericality_of :latitude, :longitude
10 validate :validate_position
11 validates_associated :changeset
16 errors.add_to_base("Node is not in the world") unless in_world?
19 def self.from_node(node)
20 old_node = OldNode.new
21 old_node.latitude = node.latitude
22 old_node.longitude = node.longitude
23 old_node.visible = node.visible
24 old_node.tags = node.tags
25 old_node.timestamp = node.timestamp
26 old_node.changeset_id = node.changeset_id
28 old_node.version = node.version
33 doc = OSM::API.new.get_xml_doc
34 doc.root << to_xml_node()
39 el1 = XML::Node.new 'node'
40 el1['id'] = self.id.to_s
41 el1['lat'] = self.lat.to_s
42 el1['lon'] = self.lon.to_s
43 el1['changeset'] = self.changeset.id.to_s
44 if self.changeset.user.data_public?
45 el1['user'] = self.changeset.user.display_name
46 el1['uid'] = self.changeset.user.id.to_s
49 self.tags.each do |k,v|
50 el2 = XML::Node.new('tag')
56 el1['visible'] = self.visible.to_s
57 el1['timestamp'] = self.timestamp.xmlschema
58 el1['version'] = self.version.to_s
62 def save_with_dependencies!
64 #not sure whats going on here
65 clear_aggregation_cache
66 clear_association_cache
68 @attributes.update(OldNode.find(:first, :conditions => ['id = ? AND timestamp = ? AND version = ?', self.id, self.timestamp, self.version]).instance_variable_get('@attributes'))
70 self.tags.each do |k,v|
75 tag.version = self.version
83 OldNodeTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
87 @tags = Hash.new unless @tags
99 # Pretend we're not in any ways
104 # Pretend we're not in any relations
105 def containing_relation_members