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"] = node_id.to_s
52 add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
59 add_tags_to_xml_node(el, old_tags)
64 def save_with_dependencies!
78 @tags ||= Hash[old_tags.collect { |t| [t.k, t.v] }]
87 # Pretend we're not in any ways
92 # Pretend we're not in any relations
93 def containing_relation_members
97 # check whether this element is the latest version - that is,
98 # has the same version as its "current" counterpart.
99 def is_latest_version?
100 current_node.version == version