1 # == Schema Information
5 # node_id :bigint(8) not null, primary key
6 # latitude :integer not null
7 # longitude :integer not null
8 # changeset_id :bigint(8) not null
9 # visible :boolean not null
10 # timestamp :datetime not null
11 # tile :bigint(8) not null
12 # version :bigint(8) not null, primary key
13 # redaction_id :integer
17 # nodes_changeset_id_idx (changeset_id)
18 # nodes_tile_idx (tile)
19 # nodes_timestamp_idx (timestamp)
23 # nodes_changeset_id_fkey (changeset_id => changesets.id)
24 # nodes_redaction_id_fkey (redaction_id => redactions.id)
27 class OldNode < ApplicationRecord
29 include ConsistencyValidations
30 include ObjectMetadata
32 self.table_name = "nodes"
33 self.primary_keys = "node_id", "version"
35 # NOTE: this needs to be included after the table name changes, or
36 # the queries generated by Redactable will use the wrong table name.
39 validates :changeset, :presence => true, :associated => true
40 validates :latitude, :presence => true,
41 :numericality => { :only_integer => true }
42 validates :longitude, :presence => true,
43 :numericality => { :only_integer => true }
44 validates :timestamp, :presence => true
45 validates :visible, :inclusion => [true, false]
47 validate :validate_position
51 belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
53 has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version]
56 errors.add(:base, "Node is not in the world") unless in_world?
59 def self.from_node(node)
60 old_node = OldNode.new
61 old_node.latitude = node.latitude
62 old_node.longitude = node.longitude
63 old_node.visible = node.visible
64 old_node.tags = node.tags
65 old_node.timestamp = node.timestamp
66 old_node.changeset_id = node.changeset_id
67 old_node.node_id = node.id
68 old_node.version = node.version
73 doc = OSM::API.new.get_xml_doc
74 doc.root << to_xml_node
78 def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
79 el = XML::Node.new "node"
80 el["id"] = node_id.to_s
82 add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
89 add_tags_to_xml_node(el, old_tags)
94 def save_with_dependencies!
101 tag.node_id = node_id
102 tag.version = version
108 @tags ||= Hash[old_tags.collect { |t| [t.k, t.v] }]
117 # Pretend we're not in any ways
122 # Pretend we're not in any relations
123 def containing_relation_members
127 # check whether this element is the latest version - that is,
128 # has the same version as its "current" counterpart.
129 def is_latest_version?
130 current_node.version == version