1 class OldNode < ActiveRecord::Base
3 include ConsistencyValidations
7 # Should probably have the composite primary key set in the model
8 # however there are some weird bugs happening when you do
9 #set_primary_keys :id, :version
11 validates_presence_of :changeset_id, :timestamp
12 validates_inclusion_of :visible, :in => [ true, false ]
13 validates_numericality_of :latitude, :longitude
14 validate :validate_position
15 validates_associated :changeset
20 errors.add(:base, "Node is not in the world") unless in_world?
23 def self.from_node(node)
24 old_node = OldNode.new
25 old_node.latitude = node.latitude
26 old_node.longitude = node.longitude
27 old_node.visible = node.visible
28 old_node.tags = node.tags
29 old_node.timestamp = node.timestamp
30 old_node.changeset_id = node.changeset_id
32 old_node.version = node.version
37 doc = OSM::API.new.get_xml_doc
38 doc.root << to_xml_node()
43 el1 = XML::Node.new 'node'
44 el1['id'] = self.id.to_s
45 el1['lat'] = self.lat.to_s
46 el1['lon'] = self.lon.to_s
47 el1['changeset'] = self.changeset.id.to_s
48 if self.changeset.user.data_public?
49 el1['user'] = self.changeset.user.display_name
50 el1['uid'] = self.changeset.user.id.to_s
53 self.tags.each do |k,v|
54 el2 = XML::Node.new('tag')
60 el1['visible'] = self.visible.to_s
61 el1['timestamp'] = self.timestamp.xmlschema
62 el1['version'] = self.version.to_s
66 def save_with_dependencies!
68 #not sure whats going on here
69 clear_aggregation_cache
70 clear_association_cache
72 @attributes.update(OldNode.find(:first, :conditions => ['id = ? AND timestamp = ? AND version = ?', self.id, self.timestamp, self.version]).instance_variable_get('@attributes'))
74 self.tags.each do |k,v|
79 tag.version = self.version
87 OldNodeTag.find(:all, :conditions => ["id = ? AND version = ?", self.id, self.version]).each do |tag|
91 @tags = Hash.new unless @tags
103 # Pretend we're not in any ways
108 # Pretend we're not in any relations
109 def containing_relation_members