1 # == Schema Information
5 # way_id :bigint(8) default(0), 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
25 include ObjectMetadata
27 self.table_name = "ways"
28 self.primary_keys = "way_id", "version"
30 # NOTE: this needs to be included after the table name changes, or
31 # the queries generated by Redactable will use the wrong table name.
36 belongs_to :current_way, :class_name => "Way", :foreign_key => "way_id"
38 has_many :old_nodes, :class_name => "OldWayNode", :foreign_key => [:way_id, :version]
39 has_many :old_tags, :class_name => "OldWayTag", :foreign_key => [:way_id, :version]
41 validates :changeset, :presence => true, :associated => true
42 validates :timestamp, :presence => true
43 validates :visible, :inclusion => [true, false]
45 def self.from_way(way)
47 old_way.visible = way.visible
48 old_way.changeset_id = way.changeset_id
49 old_way.timestamp = way.timestamp
50 old_way.way_id = way.id
51 old_way.version = way.version
53 old_way.tags = way.tags
57 def save_with_dependencies!
72 nd.id = [way_id, version, sequence]
80 @nds ||= old_nodes.order(:sequence_id).collect(&:node_id)
84 @tags ||= Hash[old_tags.collect { |t| [t.k, t.v] }]
87 attr_writer :nds, :tags
89 def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
90 el = XML::Node.new "way"
91 el["id"] = way_id.to_s
93 add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
95 old_nodes.each do |nd| # FIXME: need to make sure they come back in the right order
96 node_el = XML::Node.new "nd"
97 node_el["ref"] = nd.node_id.to_s
101 add_tags_to_xml_node(el, old_tags)
106 # Temporary method to match interface to ways
111 # Pretend we're not in any relations
112 def containing_relation_members
116 # check whether this element is the latest version - that is,
117 # has the same version as its "current" counterpart.
118 def is_latest_version?
119 current_way.version == version