]> git.openstreetmap.org Git - rails.git/commitdiff
Reimplement User#is_friends_with? in a non-insane way
authorTom Hughes <tom@compton.nu>
Sat, 23 Mar 2013 16:27:33 +0000 (16:27 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 24 Mar 2013 09:52:03 +0000 (09:52 +0000)
app/models/user.rb

index ef0dcc4b0f150a9f5c99942b8a819938e07b24e7..2e312119f8d13e669e7b941890b65932d18ca837 100644 (file)
@@ -142,14 +142,7 @@ class User < ActiveRecord::Base
   end
 
   def is_friends_with?(new_friend)
   end
 
   def is_friends_with?(new_friend)
-    res = false
-    @new_friend = new_friend
-    self.friends.each do |friend|
-      if friend.friend_user_id == @new_friend.id
-        return true
-      end
-    end
-    return false
+    self.friends.where(:friend_user_id => new_friend.id).exists?
   end
 
   ##
   end
 
   ##