- has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation, :extend => ObjectFinder
-
- def self.from_xml(xml, create=false)
- begin
- p = XML::Parser.new
- p.string = xml
- doc = p.parse
-
- doc.find('//osm/way').each do |pt|
- return Way.from_xml_node(pt, create)
- end
- rescue
- return nil
+ has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
+
+ validates_presence_of :id, :on => :update
+ validates_presence_of :changeset_id, :version, :timestamp
+ validates_uniqueness_of :id
+ validates_inclusion_of :visible, :in => [true, false]
+ validates_numericality_of :changeset_id, :version, :integer_only => true
+ validates_numericality_of :id, :on => :update, :integer_only => true
+ validates_associated :changeset
+
+ scope :visible, -> { where(:visible => true) }
+ scope :invisible, -> { where(:visible => false) }
+
+ # Read in xml as text and return it's Way object representation
+ def self.from_xml(xml, create = false)
+ p = XML::Parser.string(xml)
+ doc = p.parse
+
+ doc.find("//osm/way").each do |pt|
+ return Way.from_xml_node(pt, create)