Optimise finding of relations, partially reversing change #8443 but in
[rails.git] / app / models / relation.rb
index 9ee118f6e0c22fb26f4bff0012e30e3cb2c92173..5d7092908baa302c868cf8725378fb7d43763355 100644 (file)
@@ -105,6 +105,24 @@ class Relation < ActiveRecord::Base
     return el1
   end 
 
+  def self.find_for_nodes(ids, options = {})
+    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
+
+  def self.find_for_ways(ids, options = {})
+    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
+
+  def self.find_for_relations(ids, options = {})
+    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
+
   # FIXME is this really needed?
   def members
     unless @members