Forum: Ruby on Rails Query Help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-04-09 10:42
In my App ..i have Userinfo and FriendsInfo table.Each user has many
friends.those friends are user of the app.
for example i have 3 users in my userinfo table.namely
      =>John
      =>Victor
      =>Masvi

the users can add other users as friends.the user john has friends as
victor and masvi.these information i have stored in my FriendsInfo
table.
friendstable structure
id user_id friend_id
1    1       2
1    1       3

if i want to find who are friends of the john..
i do query like this @friends = Userinfo.find(:all,:conditions =>
{:user_id => params[user_id]})
so i will be getting all the friends id of john(his id is 1)
the @friends result set is array.
if i want display the friends name of john means
i do query like this
@friends_name = Array.new
@friends.each do |f|
  @name = Userinfo.find_by_id(f.friend_id)
  @friends_name << @name
end

how can i optimise my queries to get the above friends name...

pls help
This topic is locked and can not be replied to.