1 # == Schema Information
5 # way_id :bigint(8) not null, primary key
6 # changeset_id :bigint(8) not null
7 # timestamp :datetime not null
8 # version :bigint(8) not null, primary key
9 # visible :boolean default(TRUE), not null
10 # redaction_id :integer
14 # ways_changeset_id_idx (changeset_id)
15 # ways_timestamp_idx (timestamp)
19 # ways_changeset_id_fkey (changeset_id => changesets.id)
20 # ways_redaction_id_fkey (redaction_id => redactions.id)
23 class OldWay < ApplicationRecord
24 include ConsistencyValidations
26 self.table_name = "ways"
27 self.primary_keys = "way_id", "version"
29 # NOTE: this needs to be included after the table name changes, or
30 # the queries generated by Redactable will use the wrong table name.
34 belongs_to :redaction, :optional => true
35 belongs_to :current_way, :class_name => "Way", :foreign_key => "way_id", :inverse_of => :old_ways
37 has_many :old_nodes, :class_name => "OldWayNode", :foreign_key => [:way_id, :version], :inverse_of => :old_way
38 has_many :old_tags, :class_name => "OldWayTag", :foreign_key => [:way_id, :version], :inverse_of => :old_way
40 validates :changeset, :associated => true
41 validates :timestamp, :presence => true
42 validates :visible, :inclusion => [true, false]
44 def self.from_way(way)
46 old_way.visible = way.visible
47 old_way.changeset_id = way.changeset_id
48 old_way.timestamp = way.timestamp
49 old_way.way_id = way.id
50 old_way.version = way.version
52 old_way.tags = way.tags
56 def save_with_dependencies!
71 nd.id = [way_id, version, sequence]
79 @nds ||= old_nodes.order(:sequence_id).collect(&:node_id)
83 @tags ||= old_tags.to_h { |t| [t.k, t.v] }
86 attr_writer :nds, :tags
88 # Temporary method to match interface to 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_way.version == version