]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
changing the belongs_to and has_many items in the models to reflect the new foriegn...
[rails.git] / app / models / relation.rb
index eb3b06a130bc1a22c0f27170aabb0d2dc21c6c0b..bb8f2d00342de67fedac105ae3d6136c478b6f25 100644 (file)
@@ -3,7 +3,7 @@ class Relation < ActiveRecord::Base
   
   set_table_name 'current_relations'
 
-  belongs_to :user
+  belongs_to :changeset
 
   has_many :old_relations, :foreign_key => 'id', :order => 'version'
 
@@ -112,6 +112,36 @@ class Relation < ActiveRecord::Base
     return el1
   end 
 
+  def self.find_for_nodes(ids, options = {})
+    if ids.empty?
+      return []
+    else
+      self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'node' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
+        return self.find(:all, options)
+      end
+    end
+  end
+
+  def self.find_for_ways(ids, options = {})
+    if ids.empty?
+      return []
+    else
+      self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'way' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
+        return self.find(:all, options)
+      end
+    end
+  end
+
+  def self.find_for_relations(ids, options = {})
+    if ids.empty?
+      return []
+    else
+      self.with_scope(:find => { :joins => "INNER JOIN current_relation_members ON current_relation_members.id = current_relations.id", :conditions => "current_relation_members.member_type = 'relation' AND current_relation_members.member_id IN (#{ids.join(',')})" }) do
+        return self.find(:all, options)
+      end
+    end
+  end
+
   # FIXME is this really needed?
   def members
     unless @members