myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2153] trunk/app/models/user.rb: SQL improvement


From: noreply
Subject: [myexperiment-hackers] [2153] trunk/app/models/user.rb: SQL improvement for friendship_from_self_id_and_friends_id().
Date: Tue, 31 Mar 2009 10:39:10 -0400 (EDT)

Revision
2153
Author
dtm
Date
2009-03-31 10:39:09 -0400 (Tue, 31 Mar 2009)

Log Message

SQL improvement for friendship_from_self_id_and_friends_id().

Modified Paths

Diff

Modified: trunk/app/models/user.rb (2152 => 2153)


--- trunk/app/models/user.rb	2009-03-31 14:21:28 UTC (rev 2152)
+++ trunk/app/models/user.rb	2009-03-31 14:39:09 UTC (rev 2153)
@@ -528,17 +528,12 @@
   # 1) the ID of a user (of 2 involved in the 'friendship') who is a 'friend', not an owner of the friendship;
   # 2) the 'friendship' object itself
   def friendship_from_self_id_and_friends_id(friend_id)
-    friendship = Friendship.find(:first, :conditions => [ "user_id = ? AND friend_id = ?", id, friend_id ] )
+    friendship = Friendship.find(:first, :conditions => [ "( (user_id = ? AND friend_id = ?) OR ( user_id = ? AND friend_id = ? ) )", id, friend_id, friend_id, id ] )
     
     if friendship
       return [friend_id, friendship]
-    elsif
-      friendship = Friendship.find(:first, :conditions => [ "user_id = ? AND friend_id = ?", friend_id, id ] )
-      if friendship
-        return [id, friendship]
-      else
-        return [nil, nil] # an error state
-      end
+    else
+      return [nil, nil] # an error state
     end
   end
   

reply via email to

[Prev in Thread] Current Thread [Next in Thread]