1 class OldNode < ActiveRecord::Base
3 include ConsistencyValidations
6 self.table_name = "nodes"
7 self.primary_keys = "node_id", "version"
9 validates_presence_of :changeset_id, :timestamp
10 validates_inclusion_of :visible, :in => [ true, false ]
11 validates_numericality_of :latitude, :longitude
12 validate :validate_position
13 validates_associated :changeset
17 belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
20 errors.add(:base, "Node is not in the world") unless in_world?
23 def self.from_node(node)
24 old_node = OldNode.new
25 old_node.latitude = node.latitude
26 old_node.longitude = node.longitude
27 old_node.visible = node.visible
28 old_node.tags = node.tags
29 old_node.timestamp = node.timestamp
30 old_node.changeset_id = node.changeset_id
31 old_node.node_id = node.id
32 old_node.version = node.version
37 doc = OSM::API.new.get_xml_doc
38 doc.root << to_xml_node()
43 el1 = XML::Node.new 'node'
44 el1['id'] = self.node_id.to_s
45 el1['lat'] = self.lat.to_s
46 el1['lon'] = self.lon.to_s
47 el1['changeset'] = self.changeset.id.to_s
48 if self.changeset.user.data_public?
49 el1['user'] = self.changeset.user.display_name
50 el1['uid'] = self.changeset.user.id.to_s
53 self.tags.each do |k,v|
54 el2 = XML::Node.new('tag')
60 el1['visible'] = self.visible.to_s
61 el1['timestamp'] = self.timestamp.xmlschema
62 el1['version'] = self.version.to_s
66 def save_with_dependencies!
68 #not sure whats going on here
69 clear_aggregation_cache
70 clear_association_cache
72 @attributes.update(OldNode.where(:node_id => self.node_id, :timestamp => self.timestamp, :version => self.version).first.instance_variable_get('@attributes'))
74 self.tags.each do |k,v|
78 tag.node_id = self.node_id
79 tag.version = self.version
87 OldNodeTag.where(:node_id => self.node_id, :version => self.version).each do |tag|
91 @tags = Hash.new unless @tags
103 # Pretend we're not in any ways
108 # Pretend we're not in any relations
109 def containing_relation_members
113 # check whether this element is the latest version - that is,
114 # has the same version as its "current" counterpart.
115 def is_latest_version?
116 current_node.version == self.version