1 class OldNode < ActiveRecord::Base
3 include ConsistencyValidations
6 self.table_name = "nodes"
7 self.primary_keys = "node_id", "version"
9 # note this needs to be included after the table name changes, or
10 # the queries generated by Redactable will use the wrong table name.
13 validates_presence_of :changeset_id, :timestamp
14 validates_inclusion_of :visible, :in => [ true, false ]
15 validates_numericality_of :latitude, :longitude
16 validate :validate_position
17 validates_associated :changeset
21 belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
24 errors.add(:base, "Node is not in the world") unless in_world?
27 def self.from_node(node)
28 old_node = OldNode.new
29 old_node.latitude = node.latitude
30 old_node.longitude = node.longitude
31 old_node.visible = node.visible
32 old_node.tags = node.tags
33 old_node.timestamp = node.timestamp
34 old_node.changeset_id = node.changeset_id
35 old_node.node_id = node.id
36 old_node.version = node.version
41 doc = OSM::API.new.get_xml_doc
42 doc.root << to_xml_node()
46 def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
47 el1 = XML::Node.new 'node'
48 el1['id'] = self.node_id.to_s
49 add_metadata_to_xml_node(el1, self, changeset_cache, user_display_name_cache)
52 el1['lat'] = self.lat.to_s
53 el1['lon'] = self.lon.to_s
56 self.tags.each do |k,v|
57 el2 = XML::Node.new('tag')
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