Forum: Ruby on Rails Query Help

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Newb N. (Guest)
on 2009-04-09 12: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

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
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 =
@friends.each do |f|
  @name = Userinfo.find_by_id(f.friend_id)
  @friends_name << @name

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

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