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
30 self.table_name = "nodes"
32 # NOTE: this needs to be included after the table name changes, or
33 # the queries generated by Redactable will use the wrong table name.
36 validates :changeset, :associated => true
37 validates :latitude, :presence => true,
38 :numericality => { :only_integer => true }
39 validates :longitude, :presence => true,
40 :numericality => { :only_integer => true }
41 validates :timestamp, :presence => true
42 validates :visible, :inclusion => [true, false]
44 validate :validate_position
47 belongs_to :redaction, :optional => true
48 belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id", :inverse_of => :old_nodes
50 has_many :old_tags, :class_name => "OldNodeTag", :query_constraints => [:node_id, :version], :inverse_of => :old_node
53 errors.add(:base, "Node is not in the world") unless in_world?
56 def self.from_node(node)
57 old_node = OldNode.new
58 old_node.latitude = node.latitude
59 old_node.longitude = node.longitude
60 old_node.visible = node.visible
61 old_node.tags = node.tags
62 old_node.timestamp = node.timestamp
63 old_node.changeset_id = node.changeset_id
64 old_node.node_id = node.id
65 old_node.version = node.version
69 def save_with_dependencies!
83 @tags ||= old_tags.to_h { |t| [t.k, t.v] }
88 # Pretend we're not in any ways
93 # Pretend we're not in any relations
94 def containing_relation_members
98 # check whether this element is the latest version - that is,
99 # has the same version as its "current" counterpart.
101 current_node.version == version