1 class OldNode < ActiveRecord::Base
3 include ConsistencyValidations
5 self.table_name = "nodes"
6 self.primary_keys = "node_id", "version"
8 validates_presence_of :changeset_id, :timestamp
9 validates_inclusion_of :visible, :in => [ true, false ]
10 validates_numericality_of :latitude, :longitude
11 validate :validate_position
12 validates_associated :changeset
17 errors.add(:base, "Node is not in the world") unless in_world?
20 def self.from_node(node)
21 old_node = OldNode.new
22 old_node.latitude = node.latitude
23 old_node.longitude = node.longitude
24 old_node.visible = node.visible
25 old_node.tags = node.tags
26 old_node.timestamp = node.timestamp
27 old_node.changeset_id = node.changeset_id
28 old_node.node_id = node.id
29 old_node.version = node.version
34 doc = OSM::API.new.get_xml_doc
35 doc.root << to_xml_node()
40 el1 = XML::Node.new 'node'
41 el1['id'] = self.node_id.to_s
42 el1['lat'] = self.lat.to_s
43 el1['lon'] = self.lon.to_s
44 el1['changeset'] = self.changeset.id.to_s
45 if self.changeset.user.data_public?
46 el1['user'] = self.changeset.user.display_name
47 el1['uid'] = self.changeset.user.id.to_s
50 self.tags.each do |k,v|
51 el2 = XML::Node.new('tag')
57 el1['visible'] = self.visible.to_s
58 el1['timestamp'] = self.timestamp.xmlschema
59 el1['version'] = self.version.to_s
63 def save_with_dependencies!
65 #not sure whats going on here
66 clear_aggregation_cache
67 clear_association_cache
69 @attributes.update(OldNode.where(:node_id => self.node_id, :timestamp => self.timestamp, :version => self.version).first.instance_variable_get('@attributes'))
71 self.tags.each do |k,v|
75 tag.node_id = self.node_id
76 tag.version = self.version
84 OldNodeTag.where(:node_id => self.node_id, :version => self.version).each do |tag|
88 @tags = Hash.new unless @tags
100 # Pretend we're not in any ways
105 # Pretend we're not in any relations
106 def containing_relation_members