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 :changeset, :presence => true, :associated => true
14 validates :latitude, :presence => true,
15 :numericality => { :integer_only => true }
16 validates :longitude, :presence => true,
17 :numericality => { :integer_only => true }
18 validates :timestamp, :presence => true
19 validates :visible, :inclusion => [true, false]
21 validate :validate_position
25 belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
27 has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version]
30 errors.add(:base, "Node is not in the world") unless in_world?
33 def self.from_node(node)
34 old_node = OldNode.new
35 old_node.latitude = node.latitude
36 old_node.longitude = node.longitude
37 old_node.visible = node.visible
38 old_node.tags = node.tags
39 old_node.timestamp = node.timestamp
40 old_node.changeset_id = node.changeset_id
41 old_node.node_id = node.id
42 old_node.version = node.version
47 doc = OSM::API.new.get_xml_doc
48 doc.root << to_xml_node
52 def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
53 el = XML::Node.new "node"
54 el["id"] = node_id.to_s
56 add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
63 add_tags_to_xml_node(el, old_tags)
68 def save_with_dependencies!
82 @tags ||= Hash[old_tags.collect { |t| [t.k, t.v] }]
91 # Pretend we're not in any ways
96 # Pretend we're not in any relations
97 def containing_relation_members
101 # check whether this element is the latest version - that is,
102 # has the same version as its "current" counterpart.
103 def is_latest_version?
104 current_node.version == version