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"
23 has_many :old_tags, :class_name => 'OldNodeTag', :foreign_key => [:node_id, :version]
26 errors.add(:base, "Node is not in the world") unless in_world?
29 def self.from_node(node)
30 old_node = OldNode.new
31 old_node.latitude = node.latitude
32 old_node.longitude = node.longitude
33 old_node.visible = node.visible
34 old_node.tags = node.tags
35 old_node.timestamp = node.timestamp
36 old_node.changeset_id = node.changeset_id
37 old_node.node_id = node.id
38 old_node.version = node.version
43 doc = OSM::API.new.get_xml_doc
44 doc.root << to_xml_node()
48 def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
49 el = XML::Node.new 'node'
50 el['id'] = self.node_id.to_s
52 add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
55 el['lat'] = self.lat.to_s
56 el['lon'] = self.lon.to_s
59 add_tags_to_xml_node(el, self.old_tags)
64 def save_with_dependencies!
67 self.tags.each do |k,v|
71 tag.node_id = self.node_id
72 tag.version = self.version
78 @tags ||= Hash[self.old_tags.collect { |t| [t.k, t.v] }]
89 # Pretend we're not in any ways
94 # Pretend we're not in any relations
95 def containing_relation_members
99 # check whether this element is the latest version - that is,
100 # has the same version as its "current" counterpart.
101 def is_latest_version?
102 current_node.version == self.version