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
31 self.table_name = "nodes"
32 self.primary_keys = "node_id", "version"
34 # NOTE: this needs to be included after the table name changes, or
35 # the queries generated by Redactable will use the wrong table name.
38 validates :changeset, :associated => true
39 validates :latitude, :presence => true,
40 :numericality => { :only_integer => true }
41 validates :longitude, :presence => true,
42 :numericality => { :only_integer => true }
43 validates :timestamp, :presence => true
44 validates :visible, :inclusion => [true, false]
46 validate :validate_position
49 belongs_to :redaction, :optional => true
50 belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
52 has_many :old_tags, :class_name => "OldNodeTag", :foreign_key => [:node_id, :version]
55 errors.add(:base, "Node is not in the world") unless in_world?
58 def self.from_node(node)
59 old_node = OldNode.new
60 old_node.latitude = node.latitude
61 old_node.longitude = node.longitude
62 old_node.visible = node.visible
63 old_node.tags = node.tags
64 old_node.timestamp = node.timestamp
65 old_node.changeset_id = node.changeset_id
66 old_node.node_id = node.id
67 old_node.version = node.version
71 def save_with_dependencies!
85 @tags ||= old_tags.to_h { |t| [t.k, t.v] }
94 # Pretend we're not in any ways
99 # Pretend we're not in any relations
100 def containing_relation_members
104 # check whether this element is the latest version - that is,
105 # has the same version as its "current" counterpart.
106 def is_latest_version?
107 current_node.version == version