+ has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
+
+ validates :id, :uniqueness => true, :presence => { :on => :update },
+ :numericality => { :on => :update, :integer_only => true }
+ validates :version, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :changeset_id, :presence => true,
+ :numericality => { :integer_only => true }
+ validates :timestamp, :presence => true
+ validates :changeset, :associated => true
+ validates :visible, :inclusion => [true, false]
+
+ scope :visible, -> { where(:visible => true) }
+ scope :invisible, -> { where(:visible => false) }
+ scope :nodes, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Node", :member_id => ids.flatten }) }
+ scope :ways, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Way", :member_id => ids.flatten }) }
+ scope :relations, ->(*ids) { joins(:relation_members).where(:current_relation_members => { :member_type => "Relation", :member_id => ids.flatten }) }
+
+ TYPES = %w(node way relation)
+
+ def self.from_xml(xml, create = false)
+ p = XML::Parser.string(xml)
+ doc = p.parse
+
+ doc.find("//osm/relation").each do |pt|
+ return Relation.from_xml_node(pt, create)
+ end
+ fail OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
+ rescue LibXML::XML::Error, ArgumentError => ex
+ raise OSM::APIBadXMLError.new("relation", xml, ex.message)
+ end