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~5699 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/8ed6d80b0d254fbbaf0f64d08041c97c8da671d0 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 ##