]> git.openstreetmap.org Git - rails.git/commitdiff
Cope with being asked to find relations for any empty set of objects.
authorTom Hughes <tom@compton.nu>
Fri, 18 Jul 2008 13:13:28 +0000 (13:13 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 18 Jul 2008 13:13:28 +0000 (13:13 +0000)
app/models/relation.rb

index 5d7092908baa302c868cf8725378fb7d43763355..c8516b58a3441c9f3b0ec38262d7628c8888d00f 100644 (file)
@@ -106,20 +106,32 @@ class Relation < ActiveRecord::Base
   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)
+    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 = {})
-    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)
+    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 = {})
-    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)
+    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