1 class OldNode < ActiveRecord::Base
3 include ConsistencyValidations
6 self.table_name = "nodes"
7 self.primary_keys = "node_id", "version"
9 # note this needs to be included after the table name changes, or
10 # the queries generated by Redactable will use the wrong table name.
13 validates_presence_of :changeset_id, :timestamp
14 validates_inclusion_of :visible, :in => [ true, false ]
15 validates_numericality_of :latitude, :longitude
16 validate :validate_position
17 validates_associated :changeset
21 belongs_to :current_node, :class_name => "Node", :foreign_key => "node_id"
23 has_many :old_tags, :class_name => 'OldNodeTag', :foreign_key => [:node_id, :version]
26 errors.add(:base, "Node is not in the world") unless in_world?
29 def self.from_node(node)
30 old_node = OldNode.new
31 old_node.latitude = node.latitude
32 old_node.longitude = node.longitude
33 old_node.visible = node.visible
34 old_node.tags = node.tags
35 old_node.timestamp = node.timestamp
36 old_node.changeset_id = node.changeset_id
37 old_node.node_id = node.id
38 old_node.version = node.version
43 doc = OSM::API.new.get_xml_doc
44 doc.root << to_xml_node()
48 def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
49 el = XML::Node.new 'node'
50 el['id'] = self.node_id.to_s
52 add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache)
55 el['lat'] = self.lat.to_s
56 el['lon'] = self.lon.to_s
59 add_tags_to_xml_node(el, self.old_tags)
64 def save_with_dependencies!
66 #not sure whats going on here
67 clear_aggregation_cache
68 clear_association_cache
70 @attributes.update(OldNode.where(:node_id => self.node_id, :timestamp => self.timestamp, :version => self.version).first.instance_variable_get('@attributes'))
72 self.tags.each do |k,v|
76 tag.node_id = self.node_id
77 tag.version = self.version
85 self.old_tags.each do |tag|
89 @tags = Hash.new unless @tags
101 # Pretend we're not in any ways
106 # Pretend we're not in any relations
107 def containing_relation_members
111 # check whether this element is the latest version - that is,
112 # has the same version as its "current" counterpart.
113 def is_latest_version?
114 current_node.version == self.version