From: Tom Hughes Date: Sat, 23 Mar 2013 16:27:33 +0000 (+0000) Subject: Reimplement User#is_friends_with? in a non-insane way X-Git-Tag: live~5677^2~13^2~7 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/abd29001a31695ffdfbb731725a5cded74bce6e6 Reimplement User#is_friends_with? in a non-insane way --- diff --git a/app/models/user.rb b/app/models/user.rb index ef0dcc4b0..2e312119f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -142,14 +142,7 @@ class User < ActiveRecord::Base 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 ##