+ self.table_name = "current_nodes"
+
+ belongs_to :changeset
+
+ has_many :old_nodes, -> { order(:version) }
+
+ has_many :way_nodes
+ has_many :ways, :through => :way_nodes
+
+ has_many :node_tags
+
+ has_many :old_way_nodes
+ has_many :ways_via_history, :class_name => "Way", :through => :old_way_nodes, :source => :way
+
+ has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
+ has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
+
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :only_integer => true }
+ validates :version, :presence => true,
+ :numericality => { :only_integer => true }
+ validates :changeset_id, :presence => true,
+ :numericality => { :only_integer => true }
+ validates :latitude, :presence => true,
+ :numericality => { :only_integer => true }
+ validates :longitude, :presence => true,
+ :numericality => { :only_integer => true }
+ validates :timestamp, :presence => true
+ validates :changeset, :associated => true
+ validates :visible, :inclusion => [true, false]
+
+ validate :validate_position
+
+ scope :visible, -> { where(:visible => true) }
+ scope :invisible, -> { where(:visible => false) }
+
+ # Sanity check the latitude and longitude and add an error if it's broken
+ def validate_position
+ errors.add(:base, "Node is not in the world") unless in_world?
+ end
+
+ # Read in xml as text and return it's Node object representation
+ def self.from_xml(xml, create = false)
+ p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)