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